Configure custom axis gridlines in the SharePoint Chart Web Part

Applies to: Nevron Chart for SharePoint (WSS3.0, SharePoint 2007/2010/2013)

How to configure custom axis gridlines in the SharePoint Chart Web Part?

By default, the chart will display the axes gridlines for each major tick. You can control the default visibility and stroke style of the minor and major tick gridlines from the designer Chart areas >> Axes (Primary Y; Primary X) >> Gridlines. If you need to display custom axes gridlines, you can turn off the default ones and use custom code for your gridlines (through the designer Code tab).



The following code shows how to add custom grid lines to the Y and X axes.

The code configures the Y axis to have custom step of 5 for the automatically generated ticks/gridlines and then adds custom grid lines with step of 15.

The X axis uses the default scale step mode (configured through the designer) and adds custom grid lines with step of 1500.

[C#]
using System;
using System.Drawing;
using Nevron.GraphicsCore;
using Nevron.Chart;
using Nevron.ReportingServices;
 
namespace MyNamespace
{
    /// <summary>
    /// Sample class
    /// </summary>
    public class MyClass
    {
        /// <summary>
        /// Main entry point
        /// </summary>
        /// <param name="context"></param>
        public static void RSMain(NRSChartCodeContext context)
        {
            if (context.Document.Charts.Count == 0)
                return;
 
            // get the first chart in the document
            NChart chart = context.Document.Charts[0];
 
            if (chart.Series.Count == 0)
                return;
 
            // configure Y axis scale
            NAxis yAxis = chart.Axis(StandardAxis.PrimaryY);
            NLinearScaleConfigurator yLinearScale = yAxis.ScaleConfigurator as NLinearScaleConfigurator;
 
            // set Y standard ticks / grid lines to custom step 5
            yLinearScale.MajorTickMode = MajorTickMode.CustomStep;
            yLinearScale.CustomStep = 5;
 
            // update the Y scale definition
            yAxis.UpdateScale();
            NWallDecoratorCollection yWallDecorators = yAxis.Scale.WallDecorators;
 
            NCustomWallDecorator yWallDecorator = new NCustomWallDecorator();
 
            for (int i = 0; i < 100000; i += 15)
            {
                NGridLine yGridLine = new NGridLine(i, new NStrokeStyle(Color.Red), new ChartWallType[] { ChartWallType.Back }, false);
                yWallDecorator.WallDecorations.Add(yGridLine);
            }
 
            yWallDecorators.Add(yWallDecorator);
 
            // configure X axis scale
            NAxis xAxis = chart.Axis(StandardAxis.PrimaryX);
            NLinearScaleConfigurator xLinearScale = xAxis.ScaleConfigurator as NLinearScaleConfigurator;
 
            // set X standard ticks / grid lines to custom step 10000
            //xLinearScale.MajorTickMode = MajorTickMode.CustomStep;
            //xLinearScale.CustomStep = 10000;
 
            // update the X scale definition
            xAxis.UpdateScale();
            NWallDecoratorCollection xWallDecorators = xAxis.Scale.WallDecorators;
 
            NCustomWallDecorator xWallDecorator = new NCustomWallDecorator();
 
            for (int i = 0; i < 100000; i += 1500)
            {
                NGridLine xGridLine = new NGridLine(i, new NStrokeStyle(Color.Blue), new ChartWallType[] { ChartWallType.Back }, false);
                xWallDecorator.WallDecorations.Add(xGridLine);
            }
 
            xWallDecorators.Add(xWallDecorator);
        }
    }
}

[VB.NET]
Imports System
Imports System.Drawing
Imports Nevron.GraphicsCore
Imports Nevron.Chart
Imports Nevron.ReportingServices
 
Namespace MyNamespace
    ''' <summary>
    ''' Sample class
    ''' </summary>
    Public Class [MyClass]
        ''' <summary>
        ''' Main entry point
        ''' </summary>
        ''' <param name="context"></param>
        Public Shared Sub RSMain(context As NRSChartCodeContext)
            If context.Document.Charts.Count = 0 Then
                Return
            End If
 
            ' get the first chart in the document
            Dim chart As NChart = context.Document.Charts(0)
 
            If chart.Series.Count = 0 Then
                Return
            End If
 
            ' configure Y axis scale
            Dim yAxis As NAxis = chart.Axis(StandardAxis.PrimaryY)
            Dim yLinearScale As NLinearScaleConfigurator = TryCast(yAxis.ScaleConfigurator, NLinearScaleConfigurator)
 
            ' set Y standard ticks / grid lines to custom step 5
            yLinearScale.MajorTickMode = MajorTickMode.CustomStep
            yLinearScale.CustomStep = 5
 
            ' update the Y scale definition
            yAxis.UpdateScale()
            Dim yWallDecorators As NWallDecoratorCollection = yAxis.Scale.WallDecorators
 
            Dim yWallDecorator As New NCustomWallDecorator()
 
            For i As Integer = 0 To 99999 Step 15
                Dim yGridLine As New NGridLine(i, New NStrokeStyle(Color.Red), New ChartWallType() {ChartWallType.Back}, False)
                yWallDecorator.WallDecorations.Add(yGridLine)
            Next
 
            yWallDecorators.Add(yWallDecorator)
 
            ' configure X axis scale
            Dim xAxis As NAxis = chart.Axis(StandardAxis.PrimaryX)
            Dim xLinearScale As NLinearScaleConfigurator = TryCast(xAxis.ScaleConfigurator, NLinearScaleConfigurator)
 
            ' set X standard ticks / grid lines to custom step 10000
            'xLinearScale.MajorTickMode = MajorTickMode.CustomStep;
            'xLinearScale.CustomStep = 10000;
 
            ' update the X scale definition
            xAxis.UpdateScale()
            Dim xWallDecorators As NWallDecoratorCollection = xAxis.Scale.WallDecorators
 
            Dim xWallDecorator As New NCustomWallDecorator()
 
            For i As Integer = 0 To 99999 Step 1500
                Dim xGridLine As New NGridLine(i, New NStrokeStyle(Color.Blue), New ChartWallType() {ChartWallType.Back}, False)
                xWallDecorator.WallDecorations.Add(xGridLine)
            Next
 
            xWallDecorators.Add(xWallDecorator)
        End Sub
    End Class
End Namespace

Article ID: 205, Created On: 11/7/2011, Modified: 1/29/2013