本示例演示了在运行时刻如何定制 网格线和刻度线

要访问轴,则应该把图表的 图象 对象转换为所需的图象类型。 然后,使用 Axis2D.TickmarksAxisBase.GridLines 属性来访问相应的元素。 要指定 minor 刻度 (网格线) 的数目,则使用 AxisBase.MinorCount 属性。

C#CopyCode image复制代码
// 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;
Visual BasicCopyCode image复制代码
' Cast the chart's diagram to the XYDiagram type, to access its axes.
Dim diagram As XYDiagram = CType(chartControl1.Diagram, XYDiagram)

' 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

在下面的插图中显示了结果。

CodeCentralShow Me

在 DevExpress Code Central 数据库中可以找到完整的示例项目,网址是 http://www.devexpress.com/example=E1367。 取决于目标平台类型 (ASP.NET、WinForms 等),可以在线运行本示例,或者下载自动可执行的示例。

Expand image参阅