Nevron .NET Vision
Chart for .NET / User's Guide / Axes / Scale / Scale Configurators / Major and Minor Gridlines

In This Topic
    Major and Minor Gridlines
    In This Topic

    Gridlines appear on the chart walls and gauge background as lines with controllable color and pattern. There are two types of gridlines – those that are considered major and are by default synchronized with the values of the major scale ticks and those that are considered minor are by default synchronized with the scale minor ticks. Note that there are types of scales that do not support minor ticks - these include ordinal, price, hierarchic and timeline scale configurators.

    The appearance of major gridlines is controlled through the MajorGridStyle property of the NScaleConfigurator base abstract class.

    The appearance of minor gridlines (if supported by the scale) is controlled through the MinorGridStyle properties of the NStandardScaleConfigurator.

    Both major and minor ticks appearance properties accept an instance of the NScaleGridStyle class.

     Showing Gridlines on Chart Walls

    By default only the major grid lines associated with the vertical axes (PrimaryY and SecondaryY) are visible. The major and minor grid lines of all other axes are not visible. The following code enables the major gridlines associated with the PrimaryX axis:

    C#
    Copy Code
    NChart chart = nChartControl1.Charts[0];
    NAxis primaryX = chart.Axis(StandardAxis.PrimaryX);
    primaryX.ScaleConfigurator.MajorGridStyle.SetShowAtWall(ChartWallType.Back, true);
    
    Visual Basic
    Copy Code
    Dim chart As NChart = NChartControl1.Charts(0)
    Dim primaryX As NAxis = chart.Axis(StandardAxis.PrimaryX)
    primaryX.ScaleConfigurator.MajorGridStyle.SetShowAtWall(ChartWallType.Back, True)
    
     Changing the Gridline Appearance

    The NScaleGridStyle class has a property called LineStyle that accepts an object of type NStrokeStyle. The following code will change the appearance of the major grid lines displayed by the PrimaryY axis:

    C#
    Copy Code
    NChart chart = nChartControl1.Charts[0];
    NAxis primaryY = chart.Axis(StandardAxis.PrimaryY);
    NScaleConfigurator scaleConfigurator = primaryY.ScaleConfigurator;
    
    scaleConfigurator.MajorGridStyle.SetShowAtWall(ChartWallType.Back, true);
    scaleConfigurator.MajorGridStyle.LineStyle.Color = Color.Red;
    scaleConfigurator.MajorGridStyle.LineStyle.Width = new NLength(2, NGraphicsUnit.Point);
    
    Visual Basic
    Copy Code
    Dim chart As NChart = NChartControl1.Charts(0)
    Dim primaryY As NAxis = chart.Axis(StandardAxis.PrimaryY)
    Dim scaleConfigurator As NScaleConfigurator = primaryY.ScaleConfigurator
    
    scaleConfigurator.MajorGridStyle.SetShowAtWall(ChartWallType.Back, True)
    scaleConfigurator.MajorGridStyle.LineStyle.Color = Color.Red
    scaleConfigurator.MajorGridStyle.LineStyle.Width = New NLength(2)
    
    Major and minor grid line appearance may be altered if the grid line falls inside a scale section. Scale sections are described in the Scale Sections topic.
     Creating Grid Lines at Custom Ranges.

    NScaleGridStyle object has a property called RangeSamplerProvider provider that accepts objects that derive from the NRangeSamplerProvider object. By default the RangeSamplerProvider of the major grid style is set to NMajorTickRangeSamplerProvider. Respectively the same property for the minor grid style is set to NMinorTickRangeSamplerProvider. As the names of these two classes imply this is why by default the major grid lines are synchronized with the major ticks and the minor grid lines are synchronized with the minor ticks.

    You can change this relationship at any time by altering the range sampler provider associated with the minor and major grid line styles if you want gridlines to appear at different values. Range sampler providers are discussed in a different topic because they are also used by the NScaleStripStyle style.

    The following code will configure the major grid lines of the Y axis to show at each 5 logical units visible on the scale:

    C#
    Copy Code
    NChart chart = nChartControl1.Charts[0];
    NAxis primaryY = chart.Axis(StandardAxis.PrimaryY);
    
    NNumericRangeSamplerProvider rangeSamplerProvider = new NNumericRangeSamplerProvider();
    rangeSamplerProvider.SamplingMode = SamplingMode.CustomStep;
    rangeSamplerProvider.CustomStep = 5;
    
    
    primaryY.ScaleConfigurator.MajorGridStyle.RangeSamplerProvider = rangeSamplerProvider;
    
    Visual Basic
    Copy Code
    Dim chart As NChart = NChartControl1.Charts(0)
    Dim primaryY As NAxis = chart.Axis(StandardAxis.PrimaryY)
    
    
    Dim rangeSamplerProvider As New NNumericRangeSamplerProvider
    rangeSamplerProvider.SamplingMode = SamplingMode.CustomStep
    rangeSamplerProvider.CustomStep = 5
    
    primaryY.ScaleConfigurator.MajorGridStyle.RangeSamplerProvider = rangeSamplerProvider
    
     Related Examples
    Windows Forms: Axes \ General \ Gridlines
    See Also