We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Aligning zero on 2 y-axis

I have to y axis with ranges of -100 to 400 and -200% to 500%. When data is plotted on the graph, bar columns using the secondary y-axis start half-way up from columns on the primary y-axis. I want 0 and the primary axis and 0 on the secondary axis to be in exactly the same place. How do I do this?

Thanks
Marcus

3 Replies

RF Rashidha F Syncfusion Team May 18, 2007 01:16 PM UTC

Hi Marcus,

Thanks for using Syncfusion Products.

You can able to achieve your requirement using Axes offset property in Chart control.

The following code snippet which illustrates how to set Offset value in the primary and secondary axis.

this.chartControl1.PrimaryYAxis.Offset=45;

//if axis as a secondary axis.
axis1.Offset = 45;

Please take a look at the attached sample.

http://websamples.syncfusion.com/samples/Chart.Windows/F61144/main.htm

Let me know if this helps.

Regards,
Rashidha.


MA Marcus May 18, 2007 01:53 PM UTC

Hi,

I'm not really sure this helps because I don't want to have to define the range of values manually. How would I know what to set the Offset value to for either the primary or secondary axis?

thanks
Marcus


RR Ramya R Syncfusion Team May 21, 2007 11:01 AM UTC

Hi Marcus,

You can align the zeroth value of both PrimaryYAxis and secondaryYAxis by adjusting the location of the secondaryYAxis as shown in the code snippet below,

private float SecYLoc;
private double m;


if (axis1.Range.Min < 0)
m = -axis1.Range.Min;
else
m = axis1.Range.Min;

// To find the position of value 0 in Secondary Y axis
double n2 = (axis1.Size.Height * m) / (axis1.Range.Max - axis1.Range.Min);


SecYLoc = (float)(this.chartControl1.GetChartAreaCoordinateY(0) + n2 + this.chartControl1.ChartArea.RenderBounds.Top-this.chartControl1.ChartArea.ChartAreaMargins.Bottom);
axis1.LocationType = ChartAxisLocationType.Set;

// Changing Location of the Secondary axis to coincide 0 in both Y axes
axis1.Location = new PointF((float)(this.chartControl1.ChartArea.RenderBounds.Right), SecYLoc);

this.chartControl1.Redraw(true);

Please let me know whether this helps you.

Thanks & Regards,
Ramya.


Loader.
Live Chat Icon For mobile
Up arrow icon