Hi Alexander,
Currently, there is no build-in functionality to align the axes in this way, but you can use custom code to achieve this. The following code shows how to align two axes relative to a factor and value. The factor specifies how the value should be positioned relative to the axis range:
private void Form1_Load(object sender, EventArgs e)
{
NChart chart = (NChart)nChartControl1.Charts[0];
chart.Axis(StandardAxis.SecondaryY).Visible = true;
NBarSeries bar = new NBarSeries();
bar.Values.Add(10);
bar.Values.Add(20);
bar.Values.Add(-10);
chart.Series.Add(bar);
NLineSeries line = new NLineSeries();
line.Values.Add(100);
line.Values.Add(200);
line.Values.Add(-400);
chart.Series.Add(line);
line.DisplayOnAxis(StandardAxis.PrimaryY, false);
line.DisplayOnAxis(StandardAxis.SecondaryY, true);
AlignAxes();
}
void AlignAxes()
{
NChart chart = nChartControl1.Charts[0];
chart.Axis(StandardAxis.PrimaryY).ConstLines.Clear();
chart.Axis(StandardAxis.SecondaryY).ConstLines.Clear();
nChartControl1.RecalcLayout();
AlignAxis(chart.Axis(StandardAxis.PrimaryY), 0.5, 0);
AlignAxis(chart.Axis(StandardAxis.SecondaryY), 0.5, 0);
nChartControl1.Refresh();
}
private void AlignAxis(NAxis axis, double factor, double value)
{
NRange1DD viewRange1 = axis.Scale.RulerRange;
double valueFactor = viewRange1.GetValueFactor(value);
double includedValue = value;
if (valueFactor > factor)
{
// extend view range end
includedValue = (value - viewRange1.Begin + factor * viewRange1.Begin) / factor;
}
else if (valueFactor < factor)
{
// extend view range begin
includedValue = (factor * viewRange1.End - value) / (factor - 1);
}
axis.ConstLines.Clear();
NAxisConstLine constLine = new NAxisConstLine();
constLine.StrokeStyle.Width = new NLength(0);
constLine.Value = includedValue;
constLine.IncludeInAxisRange = true;
axis.ConstLines.Add(constLine);
}
Since both axes are aligned with the same factor and value the value is positioned relatively in the same position on the X and Y axes.
We hope this helps - let us know if you meet any problems or have any questions.
Best Regards,
Nevron Support Team