1) I add 4 series and connect these 4 series to 4 custom axes - 1 series to one custom axes
2) I use a PlaceAxes in order to put the axes in the correct positioning
3) When I first "Activate = false" and then "active =true" using 4 checkBoxes - the axes positioning is completely wrong - eventhough I call PlaceAxes after the "Activate - deactive" series.
the code is below here:
Code: Select all
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Test___Problems_with_Multiple_Axes
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
tChart1.Series.Clear();
tChart1.Series.RemoveAllSeries();
tChart1.Dock = DockStyle.Fill;
tChart1.BackColor = Color.White;
tChart1.Walls.Back.Gradient.Visible = false;
tChart1.Walls.Back.Color = Color.White;
tChart1.Walls.Bottom.Gradient.Visible = false;
tChart1.Walls.Bottom.Color = Color.White;
tChart1.Panel.Gradient.Visible = false;
tChart1.Panel.Color = Color.White;
tChart1.Aspect.View3D = false;
tChart1.Panel.Bevel.Outer = Steema.TeeChart.Drawing.BevelStyles.None;
tChart1.Axes.Left.Automatic = true;
tChart1.Axes.Bottom.Automatic = true;
tChart1.Axes.Left.Title.Caption = "";
tChart1.Axes.Bottom.Title.Caption = "";
tChart1.Header.Text = "";
tChart1.Legend.Visible = false;
tChart1.Legend.Shadow.Visible = false;
tChart1.Legend.Font.Size = 14;
tChart1.Legend.Symbol.Width = 50;
tChart1.Legend.Symbol.Squared = true;
if (tChart1.Axes.Custom.Count > 0)
{
tChart1.Axes.Custom.Clear();
}
//========== Serie 1 ==========================
Steema.TeeChart.Styles.Points Pointsseries = new Steema.TeeChart.Styles.Points(tChart1.Chart);
this.tChart1.Series.Add(Pointsseries);
Pointsseries.Title = "Super Axes 1";
Pointsseries.Color = Color.AliceBlue;
if ((tChart1.Series.Count % 2) == 0)
{
this.tChart1.Axes.Custom.Add(new Steema.TeeChart.Axis(tChart1.Chart));
this.tChart1.Axes.Custom[this.tChart1.Axes.Custom.Count - 1].OtherSide = false;
}
else
{
this.tChart1.Axes.Custom.Add(new Steema.TeeChart.Axis(tChart1.Chart));
this.tChart1.Axes.Custom[this.tChart1.Axes.Custom.Count - 1].OtherSide = true;
}
this.tChart1.Axes.Custom[tChart1.Axes.Custom.Count - 1].Title.Text = "Super Axes";
Pointsseries.CustomVertAxis = this.tChart1.Axes.Custom[tChart1.Axes.Custom.Count - 1];
this.tChart1.Panel.MarginUnits = Steema.TeeChart.PanelMarginUnits.Pixels;
Pointsseries.FillSampleValues();
//========== Serie 2 ==========================
Steema.TeeChart.Styles.Points Pointsseries2 = new Steema.TeeChart.Styles.Points(tChart1.Chart);
this.tChart1.Series.Add(Pointsseries2);
Pointsseries2.Title = "Super Axes 2";
Pointsseries2.Color = Color.LimeGreen;
if ((tChart1.Series.Count % 2) == 0)
{
this.tChart1.Axes.Custom.Add(new Steema.TeeChart.Axis(tChart1.Chart));
this.tChart1.Axes.Custom[this.tChart1.Axes.Custom.Count - 1].OtherSide = false;
}
else
{
this.tChart1.Axes.Custom.Add(new Steema.TeeChart.Axis(tChart1.Chart));
this.tChart1.Axes.Custom[this.tChart1.Axes.Custom.Count - 1].OtherSide = true;
}
this.tChart1.Axes.Custom[tChart1.Axes.Custom.Count - 1].Title.Text = "Super Axes 2";
Pointsseries2.CustomVertAxis = this.tChart1.Axes.Custom[tChart1.Axes.Custom.Count - 1];
this.tChart1.Panel.MarginUnits = Steema.TeeChart.PanelMarginUnits.Pixels;
Pointsseries2.FillSampleValues();
//========== Serie 3 ==========================
Steema.TeeChart.Styles.Points Pointsseries3 = new Steema.TeeChart.Styles.Points(tChart1.Chart);
this.tChart1.Series.Add(Pointsseries3);
Pointsseries3.Title = "Super Axes 3";
Pointsseries3.Color = Color.Blue;
if ((tChart1.Series.Count % 2) == 0)
{
this.tChart1.Axes.Custom.Add(new Steema.TeeChart.Axis(tChart1.Chart));
this.tChart1.Axes.Custom[this.tChart1.Axes.Custom.Count - 1].OtherSide = false;
}
else
{
this.tChart1.Axes.Custom.Add(new Steema.TeeChart.Axis(tChart1.Chart));
this.tChart1.Axes.Custom[this.tChart1.Axes.Custom.Count - 1].OtherSide = true;
}
this.tChart1.Axes.Custom[tChart1.Axes.Custom.Count - 1].Title.Text = "Super Axes 3";
Pointsseries3.CustomVertAxis = this.tChart1.Axes.Custom[tChart1.Axes.Custom.Count - 1];
this.tChart1.Panel.MarginUnits = Steema.TeeChart.PanelMarginUnits.Pixels;
Pointsseries3.FillSampleValues();
//========== Serie 4 ==========================
Steema.TeeChart.Styles.Points Pointsseries4 = new Steema.TeeChart.Styles.Points(tChart1.Chart);
this.tChart1.Series.Add(Pointsseries4);
Pointsseries4.Title = "Super Axes 4";
Pointsseries4.Color = Color.Red;
if ((tChart1.Series.Count % 2) == 0)
{
this.tChart1.Axes.Custom.Add(new Steema.TeeChart.Axis(tChart1.Chart));
this.tChart1.Axes.Custom[this.tChart1.Axes.Custom.Count - 1].OtherSide = false;
}
else
{
this.tChart1.Axes.Custom.Add(new Steema.TeeChart.Axis(tChart1.Chart));
this.tChart1.Axes.Custom[this.tChart1.Axes.Custom.Count - 1].OtherSide = true;
}
this.tChart1.Axes.Custom[tChart1.Axes.Custom.Count - 1].Title.Text = "Super Axes 4";
Pointsseries4.CustomVertAxis = this.tChart1.Axes.Custom[tChart1.Axes.Custom.Count - 1];
this.tChart1.Panel.MarginUnits = Steema.TeeChart.PanelMarginUnits.Pixels;
Pointsseries4.FillSampleValues();
for (int i = 0; i < tChart1.Axes.Custom.Count; i++)
{
tChart1.Axes.Custom[i].Title.Angle = 90;
tChart1.Axes.Custom[i].PositionUnits = Steema.TeeChart.PositionUnits.Pixels;
tChart1.Axes.Custom[i].Grid.Visible = false;
}
PlaceAxes(0, 0, 0, 0, 0);
}
private void saveImageToolStripMenuItem_Click(object sender, EventArgs e)
{
// set a default file name
saveFileDialog1.FileName = "unknown.JPEG";
// set filters - this can be done in properties as well
saveFileDialog1.Filter = "JPEG file (*.JPEG)|*.JPEG";
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
tChart1.Export.Image.JPEG.Save(@saveFileDialog1.FileName);
}
}
private void PlaceAxes(int nSeries, int NextXLeft, int NextXRight, int MargLeft, int MargRight)
{
const int extraPos = 50;
const int extraMargin = 105;
//Variable
int MaxLabelsWidth;
int lenghtTicks;
int extraSpaceBetweenTitleAndLabels;
if (tChart1[nSeries].Active)
{
MaxLabelsWidth = tChart1.Axes.Custom[nSeries].MaxLabelsWidth();
lenghtTicks = tChart1.Axes.Custom[nSeries].Ticks.Length;
extraSpaceBetweenTitleAndLabels = (tChart1.Axes.Custom[nSeries].Title.Width);//- tChart1.Axes.Custom[nSeries].MaxLabelsWidth());
if (tChart1.Axes.Custom[nSeries].OtherSide)
{
tChart1.Axes.Custom[nSeries].RelativePosition = NextXRight;
NextXRight = NextXRight - (MaxLabelsWidth + lenghtTicks + extraSpaceBetweenTitleAndLabels + extraPos);
MargRight = MargRight + extraMargin;
}
else
{
tChart1.Axes.Custom[nSeries].RelativePosition = NextXLeft;
NextXLeft = NextXLeft - (MaxLabelsWidth + lenghtTicks + extraSpaceBetweenTitleAndLabels + extraPos);
MargLeft = MargLeft + extraMargin;
}
tChart1.Panel.MarginLeft = MargLeft;
tChart1.Panel.MarginRight = MargRight;
nSeries++;
if (nSeries <= tChart1.Series.Count - 1)
PlaceAxes(nSeries, NextXLeft, NextXRight, MargLeft, MargRight);
}
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
tChart1[0].Active = checkBox1.Checked;
PlaceAxes(0, 0, 0, 0, 0);
}
private void checkBox2_CheckedChanged(object sender, EventArgs e)
{
tChart1[1].Active = checkBox2.Checked;
PlaceAxes(0, 0, 0, 0, 0);
}
private void checkBox3_CheckedChanged(object sender, EventArgs e)
{
tChart1[2].Active = checkBox3.Checked;
PlaceAxes(0, 0, 0, 0, 0);
}
private void checkBox4_CheckedChanged(object sender, EventArgs e)
{
tChart1[3].Active = checkBox4.Checked;
PlaceAxes(0, 0, 0, 0, 0);
}
}
}