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.
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 |
---|---|
Defines the number of minor tickmarks (gridlines) between major tickmarks (gridlines). | |
Enables minor tickmarks. | |
Specifies whether tickmarks cross the axis. | |
Sets the length of major tickmarks. | |
Specifies the thickness of major tickmarks. | |
Sets the length of minor tickmarks. | |
Specifies the thickness of minor tickmarks. | |
Enables minor gridlines. | |
Sets the major gridline color. | |
Sets the major gridline style. | |
Sets the minor gridline color. | |
Specifies the minor gridline style. |