Page 1 of 1
Align Y axis grid lines
Posted: Thu Jun 20, 2019 8:51 am
by 15686230
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?
Re: Align Y axis grid lines
Posted: Thu Jun 20, 2019 10:52 am
by Marc
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
Re: Align Y axis grid lines
Posted: Thu Jun 20, 2019 3:33 pm
by 15686230
Thanks Marc, that worked for me.