Skip to main content

How to: Customize Axis Gridlines and Tickmarks

  • 2 minutes to read

This example demonstrates how to enable and customize axis grid lines and tickmarks at runtime.

gridlines_0

To access an axis, cast the chart’s diagram object to the diagram type (for example, XYDiagram). Use the Axis2D.Tickmarks and AxisBase.GridLines properties to access tickmark and gridline settings.

using System.Drawing;
using DevExpress.XtraCharts;
//...
// Cast the chart's diagram to the XYDiagram type, to access its axes.
XYDiagram diagram = (XYDiagram)chartControl1.Diagram;

// Customize the appearance of the axes' tickmarks.
diagram.AxisX.Tickmarks.CrossAxis = true;
diagram.AxisX.Tickmarks.Length = 5;
diagram.AxisX.Tickmarks.Thickness = 2;

diagram.AxisY.Tickmarks.Visible = false;
diagram.AxisY.Tickmarks.MinorVisible = false;

diagram.AxisX.Tickmarks.MinorLength = 3;
diagram.AxisX.Tickmarks.MinorThickness = 1;

diagram.AxisX.MinorCount = 2;
diagram.AxisY.MinorCount = 4;

// Customize the appearance of the axes' grid lines.
diagram.AxisX.GridLines.Visible = false;
diagram.AxisX.GridLines.MinorVisible = false;

diagram.AxisY.GridLines.Visible = true;
diagram.AxisY.GridLines.MinorVisible = true;

diagram.AxisY.GridLines.Color = Color.Red;
diagram.AxisY.GridLines.LineStyle.DashStyle = DashStyle.Solid;
diagram.AxisY.GridLines.LineStyle.Thickness = 2;

diagram.AxisY.GridLines.MinorColor = Color.Blue;
diagram.AxisY.GridLines.MinorLineStyle.DashStyle = DashStyle.Dash;
diagram.AxisY.GridLines.MinorLineStyle.Thickness = 1;

Related API members:

Name

Description

AxisBase.MinorCount

Defines the number of minor tickmarks (gridlines) between major tickmarks (gridlines).

TickmarksBase.MinorVisible

Enables minor tickmarks.

TickmarksBase.CrossAxis

Specifies whether tickmarks cross the axis.

TickmarksBase.Length

Sets the length of major tickmarks.

TickmarksBase.Thickness

Specifies the thickness of major tickmarks.

TickmarksBase.MinorLength

Sets the length of minor tickmarks.

TickmarksBase.MinorThickness

Specifies the thickness of minor tickmarks.

GridLines.MinorVisible

Enables minor gridlines.

GridLines.Color

Sets the major gridline color.

GridLines.LineStyle

Sets the major gridline style.

GridLines.MinorColor

Sets the minor gridline color.

GridLines.MinorLineStyle

Specifies the minor gridline style.

See Also