Applies to: Nevron Chart for Reporting Services (SSRS 2005 and 2008)
How to configure custom axis gridlines in the Chart for SQL Reporting Services?
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);
}
}
}
Article ID: 204, Created On: 11/7/2011, Modified: 11/24/2011