Nevron Forum

Multiple custom Y axis

https://www.nevron.com/Forum/Topic5776.aspx

By Daniela Rybarova - Tuesday, November 1, 2011

Hello, I would ask - when I want to have three and more Y axis in the one chart must I use PrimaryY, SecondaryY and customY axis or can I use three and more customY axis? I've tried to use three custom axis and it's look like on the enclosed picture.
By Nevron Support - Tuesday, November 1, 2011

Hi Filip,

You can use only custom axes - the only restriction is that you cannot delete the standard axes.

The following code snippet shows how to create three line series, each scaling on a custom Y axis:

  private void Form1_Load(object sender, EventArgs e)
  {
   NChart chart = nChartControl1.Charts[0];

   NLineSeries line1 = CreateLineSeries(Color.Red);
   chart.Series.Add(line1);

   NLineSeries line2 = CreateLineSeries(Color.Green);
   chart.Series.Add(line2);

   NLineSeries line3 = CreateLineSeries(Color.Blue);
   chart.Series.Add(line3);

   chart.Axis(StandardAxis.PrimaryY).Visible = false;

   NAxis customAxis1 = CreateCustomAxis(chart, Color.Red);
   line1.DisplayOnAxis((int)StandardAxis.PrimaryY, false);
   line1.DisplayOnAxis(customAxis1.AxisId, true);

   NAxis customAxis2 = CreateCustomAxis(chart, Color.Green);
   line2.DisplayOnAxis((int)StandardAxis.PrimaryY, false);
   line2.DisplayOnAxis(customAxis2.AxisId, true);

   NAxis customAxis3 = CreateCustomAxis(chart, Color.Blue);
   line3.DisplayOnAxis((int)StandardAxis.PrimaryY, false);
   line3.DisplayOnAxis(customAxis3.AxisId, true);
  }

  private NAxis CreateCustomAxis(NChart chart, Color color)
  {
   NAxis customAxis = ((NCartesianAxisCollection)chart.Axes).AddCustomAxis(AxisOrientation.Vertical, AxisDockZone.FrontLeft);

   // modify the anchor so that it creates a new zone levek
   customAxis.Anchor = new NDockAxisAnchor(AxisDockZone.FrontLeft, true);

   NLinearScaleConfigurator scale = customAxis.ScaleConfigurator as NLinearScaleConfigurator;

   scale.RulerStyle.BorderStyle.Color = color;

   return customAxis;
  }

  Random rand = new Random();

  private NLineSeries CreateLineSeries(Color color)
  {
   NLineSeries line = new NLineSeries();

   line.DataLabelStyle.Visible = false;
   line.BorderStyle.Color = color;


   for (int i = 0; i < 10; i++)
   {
    line.Values.Add(rand.Next(100));
   }

   return line;
  }

Probably in your code you have to touch the axis anchor a bit (so that it does not creaete a separate scale level - check out Axes\General\Ruler Size example).

Hope this helps - let us know if you meet any problems.

 

By Daniela Rybarova - Wednesday, November 2, 2011

I've changed the Visible property of primaryY axis to false and modified the anchors of the custom axis and it it works. Thank you.