Align Y axis grid lines

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
Des
Newbie
Newbie
Posts: 3
Joined: Tue May 14, 2019 12:00 am

Align Y axis grid lines

Post by Des » Thu Jun 20, 2019 8:51 am

For a WPF chart (2D line chart with multiple series), how do you make it so the grid lines are the same (aligned) for the left and right axis with 2 variables - say pressure on left axis and elevation on right axis?

Marc
Site Admin
Site Admin
Posts: 1272
Joined: Thu Oct 16, 2003 4:00 am
Location: Girona
Contact:

Re: Align Y axis grid lines

Post by Marc » Thu Jun 20, 2019 10:52 am

Hello,

To line up the grid-lines you'll need to guarantee the same scale min/max and increments on each side. If the scales are markedly different and it's not practical to line-up the increments you could hide the pen of one of the axes' grid lines. Even if you line them up that is advisable to do so to avoid the effect of the odd pixel rounding difference on different scales.

For example:

Code: Select all

//add a couple of series to the chart
Steema.TeeChart.WPF.Styles.Line line1 = new Steema.TeeChart.WPF.Styles.Line();
Steema.TeeChart.WPF.Styles.Line line2 = new Steema.TeeChart.WPF.Styles.Line();

Random rnd = new Random();

//populate series
for (int i=0; i < 20; i++)
{
	line1.Add(rnd.Next(20));
	line2.Add(rnd.Next(30));
}

//locate the second series to the right axis
line2.VertAxis = VerticalAxis.Right;

//add series to chart
tchart1.Series.Add(line1);
tchart1.Series.Add(line2);

//line-up series. Note the dissimilar increments.
tchart1.Axes.Left.Increment = 2;
tchart1.Axes.Left.SetMinMax(0, 20);
tchart1.Axes.Right.Increment = 3;
tchart1.Axes.Right.SetMinMax(0, 30);

//there may be some slight pixel rounding issues on alignment
//optionally hide one of the axes' grid pens
tchart1.Axes.Right.Grid.Visible = false;
Here, knowing a little about the data range to be expected in the case of both series, it has been possible to line-up disimilar scales.

Regards,
Marc Meumann
Steema Support

Des
Newbie
Newbie
Posts: 3
Joined: Tue May 14, 2019 12:00 am

Re: Align Y axis grid lines

Post by Des » Thu Jun 20, 2019 3:33 pm

Thanks Marc, that worked for me.

Post Reply