Page 1 of 1

Swapping Axis

Posted: Fri Apr 20, 2007 4:14 pm
by 8739068
Is there a way to swap axes with out removing a series rebuilding it and re-adding it? In other words, I would like to be able to do the equivalent below in a more efficient manner.

Is there a way to do it for a Steema.TeeChart.Styles.Surface?

For example:

Steema.TeeChart.Styles.Line series = new Steema.TeeChart.Styles.Line();
tChart1.Series.Add(series);
series.XValues.Order = Steema.TeeChart.Styles.ValueListOrder.Ascending;
double[] x = new double[] { 10, 4, 8, 20, 18, 2, 6, 12, 16, 14};
double[] y = new double[] { 10, 25, 12.5, 5, 5.556, 50, 16.667, 8.333, 6.25, 7.1428};series.Add(x, y);
series.XValues.Sort();
series.YValues.Sort();

tChart1.Refresh();

.
.
.

// Now lets swap the x & y axis

tChart1.Series.Clear();
Steema.TeeChart.Styles.Line series = new Steema.TeeChart.Styles.Line();
tChart1.Series.Add(series);
series.XValues.Order = Steema.TeeChart.Styles.ValueListOrder.Ascending;
double[] x = new double[] { 10, 4, 8, 20, 18, 2, 6, 12, 16, 14};
double[] y = new double[] { 10, 25, 12.5, 5, 5.556, 50, 16.667, 8.333, 6.25, 7.1428};series.Add(y, x); //NOTICE: swapped X & Y
series.XValues.Sort();
series.YValues.Sort();

tChart1.Refresh();

Posted: Mon Apr 23, 2007 8:06 am
by 9348258
Hi Mikes

You can use the "3D Grid Transpose" tool, to do this in your surface series, as below code:

Code: Select all

 private void Form1_Load(object sender, EventArgs e)
        {
            surface1.FillSampleValues();
            Steema.TeeChart.Tools.GridTranspose gridTranspose1 = new Steema.TeeChart.Tools.GridTranspose(tChart1.Chart); 
            gridTranspose1.Series = surface1; 
        }

        private void button1_Click(object sender, EventArgs e)
        {
            ((Steema.TeeChart.Tools.GridTranspose)tChart1.Tools[0]).Transpose(); 
        }

follow up questions

Posted: Mon Apr 23, 2007 1:32 pm
by 8739068
You propose using a 3D grid, but what if I am using a Line series as my example shows?

Also it is very important to our design that we add points by passing in array of doubles. This is most efficient when we have thousands of points. How do you suggest we swap and X and Y axis in a Line series?

What effect will we encounter if X has a regular interval and Y does not after we swap the X and Y?

Posted: Tue Apr 24, 2007 8:21 am
by narcis
Hi Mike,
You propose using a 3D grid, but what if I am using a Line series as my example shows?
I guess this was because you asked this:
Is there a way to do it for a Steema.TeeChart.Styles.Surface?
Also it is very important to our design that we add points by passing in array of doubles. This is most efficient when we have thousands of points. How do you suggest we swap and X and Y axis in a Line series?
What you already do seems fine to me as valuelists can not be assigned directly since they are read only. The only thing I would change is not removing and creating series everytime. I would do something like this:

Code: Select all

		private double[] x = new double[] { 10, 4, 8, 20, 18, 2, 6, 12, 16, 14 };
		private double[] y = new double[] { 10, 25, 12.5, 5, 5.556, 50, 16.667, 8.333, 6.25, 7.1428 };

		private void button1_Click(object sender, EventArgs e)
		{
			tChart1[0].Clear();
			Steema.TeeChart.Styles.ValueListOrder tmpOrder = tChart1[0].XValues.Order;
			tChart1[0].XValues.Order = tChart1[0].YValues.Order;
			tChart1[0].YValues.Order = tmpOrder;

			tChart1[0].Add(y, x);
		}		

		private void Form1_Load(object sender, EventArgs e)
		{
			tChart1.Series.Clear();

			Steema.TeeChart.Styles.Line series = new Steema.TeeChart.Styles.Line();
			tChart1.Series.Add(series);
			series.XValues.Order = Steema.TeeChart.Styles.ValueListOrder.Ascending;
			series.Add(x, y);
		}
Also notice that we have implemented SeriesTransposeTool for TeeChart for .NET v3 Beta, which is available at the client download area. However, this tool doesn't behave as you request here.
What effect will we encounter if X has a regular interval and Y does not after we swap the X and Y?
Nothing should happen. Line series doesn't need to have regular intervals.