Change the axis range in Nevron Chart for .NET programmatically

Applies to: Nevron Chart for .NET

How to change the axis range in Nevron Chart for .NET programmatically?



By default all chart axes will determine their ranges based on the data displayed on them. However, if you want to force some axis to show a certain range you must apply a NRangeAxisView object to that axis. The following code shows how to setup the X and Y axes to display the range [10, 30]:

[C#]

using System;
using System.Windows.Forms;
using Nevron.Chart;
using Nevron.GraphicsCore;
...
NChart chart = nChartControl1.Charts[0];
 
chart.BoundsMode = BoundsMode.Stretch;
NPointSeries point = new NPointSeries();
point.UseXValues = true;
point.DataLabelStyle.Visible = false;
point.PointShape = PointShape.Ellipse;
Random rand = new Random();
 
for (int i = 0; i < 1000; i++)
{
    point.Values.Add(rand.Next(100));
    point.XValues.Add(rand.Next(100));
}
 
chart.Series.Add(point);
 
chart.Axis(StandardAxis.PrimaryY).View = new NRangeAxisView(new NRange1DD(10, 30), true, true);
chart.Axis(StandardAxis.PrimaryX).View = new NRangeAxisView(new NRange1DD(10, 30), true, true);

[VB.NET]
Imports Nevron.Chart
Imports Nevron.GraphicsCore
...
Dim chart As NChart = NChartControl1.Charts(0)
 
chart.BoundsMode = BoundsMode.Stretch
Dim point As New NPointSeries()
point.UseXValues = True
point.DataLabelStyle.Visible = False
point.PointShape = PointShape.Ellipse
Dim rand As New Random()
 
For i As Integer = 0 To 999
    point.Values.Add(rand.[Next](100))
    point.XValues.Add(rand.[Next](100))
Next
 
chart.Series.Add(point)
 
chart.Axis(StandardAxis.PrimaryY).View = New NRangeAxisView(New NRange1DD(10, 30), True, True)
chart.Axis(StandardAxis.PrimaryX).View = New NRangeAxisView(New NRange1DD(10, 30), True, True)

Note that the axis will still try to round to the nearest min/max tick if this is specified in the scale configurator. It is also a good idea to turn off tick rounding:

[C#]
NLinearScaleConfigurator scale = chart.Axis(StandardAxis.PrimaryY).ScaleConfigurator as NLinearScaleConfigurator;
scale.RoundToTickMax = false;
scale.RoundToTickMin = false;

[VB.NET]
Dim scale As NLinearScaleConfigurator = TryCast(chart.Axis(StandardAxis.PrimaryY).ScaleConfigurator, NLinearScaleConfigurator)
scale.RoundToTickMax = False
scale.RoundToTickMin = False


Article ID: 58, Created On: 10/6/2010, Modified: 3/29/2011