Grid Lines

GridLines are vertical and horizontal lines added in conjunction with the tick marks on the x-axis (XAxis) and tick marks on the y-axis (YAxis), respectively. Adding grid lines makes chart data easier to read and interpret. There are two types of grid lines: XAxisGridLines and YAxisGridLines, both of which are inherited from the GridLines class.

GridLines

The GridLines class is the parent of XAxisGridLines and YAxisGridLines and has the following properties for customizing a gridline's appearance.

Properties

Property Description
Color Gets or sets the Color object to use for the color of the grid lines.
Interval Gets or sets the interval of the grid lines.
LineStyle Gets or sets the LineStyle enumeration that specifies the line style of the grid lines.
Visible Gets or sets the visible status of the grid lines on the plot area. By default it is True.
Width Gets or sets the width of the grid lines.

Customizing a gridline's appearance, such as thickness or color, requires customizing the axis tick marks if you wish for a consistent appearance.

XAxisGridLines

Add XAxisGridLines vertically to a plot area setting either the MajorGridLines or MinorGridLines property in XAxis. The major gridlines are placed at the same intervals as the x-axis major tick marks, and the minor gridlines are placed at the same intervals as the x-axis minor tick marks.

The following code illustrates adding XAxisGridLines.

Chart chart = new Chart(0, 0, 300, 200);
PlotArea plotArea = chart.PrimaryPlotArea;
plotArea.XAxes.DefaultNumericXAxis.MajorGridLines = new XAxisGridLines();
plotArea.XAxes.DefaultNumericXAxis.MinorGridLines = new XAxisGridLines();        
Dim MyChart As Chart = New Chart(0, 0, 300, 200)
Dim MyPlotArea = MyChart.PrimaryPlotArea
MyPlotArea.XAxes.DefaultNumericXAxis.MajorGridLines = New XAxisGridLines()
MyPlotArea.XAxes.DefaultNumericXAxis.MinorGridLines = New XAxisGridLines()  

Refer to the XAxisGridLines API documentation for a complete example.

YAxisGridLines

Add YAxisGridLines horizontally to a plot area setting either the MajorGridLines or MinorGridLines property in YAxis. Major gridlines are placed at the same intervals as the y-axis major tick marks, and the minor gridlines are placed at the same intervals as the y-axis minor tick marks.

The following code illustrates adding YAxisGridLines.

Chart chart = new Chart(0, 0, 300, 200);
PlotArea plotArea = chart.PrimaryPlotArea;
plotArea.YAxes.DefaultNumericYAxis.MajorGridLines = new YAxisGridLines();
plotArea.YAxes.DefaultNumericYAxis.MinorGridLines = new YAxisGridLines();        
Dim MyChart As Chart = New Chart(0, 0, 300, 200)
Dim MyPlotArea = MyChart.PrimaryPlotArea
MyPlotArea.YAxes.DefaultNumericYAxis.MajorGridLines = New YAxisGridLines()
MyPlotArea.YAxes.DefaultNumericYAxis.MinorGridLines = New YAxisGridLines()

Refer to the YAxisGridLines API documentation for a complete example.

In this topic