本示例演示了在运行时刻如何创建并定制 自定义轴标签

C#CopyCode image复制代码
// Cast the chart's diagram to the XYDiagram type, to access its axes.
XYDiagram diagram = (XYDiagram)chartControl1.Diagram;

// Add two custom labels to the X-axis' collection.
diagram.AxisX.CustomLabels.Add(new CustomAxisLabel("Custom Label 1"));
diagram.AxisX.CustomLabels.Add(new CustomAxisLabel("Custom Label 2"));

// Define their AxisValue. Since the custom labels belong to the X-axis,
// this property determines the series argument, to which labels should stick.
diagram.AxisX.CustomLabels[0].AxisValue = "B";
diagram.AxisX.CustomLabels[1].AxisValue = "D";

// Customize the custom labels' appearance.
diagram.AxisX.Label.TextColor = Color.Red;
Visual BasicCopyCode image复制代码
' Cast the chart's diagram to the XYDiagram type, to access its axes.
Dim diagram As XYDiagram = CType(chartControl1.Diagram, XYDiagram)

' Add two custom labels to the X-axis' collection.
diagram.AxisX.CustomLabels.Add(New CustomAxisLabel("Custom Label 1"))
diagram.AxisX.CustomLabels.Add(New CustomAxisLabel("Custom Label 2"))

' Define their AxisValue. Since the custom labels belong to the X-axis,
' this property determines the series argument, to which labels should stick.
diagram.AxisX.CustomLabels(0).AxisValue = "B"
diagram.AxisX.CustomLabels(1).AxisValue = "D"

' Customize the custom labels' appearance.
diagram.AxisX.Label.TextColor = Color.Red

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

CodeCentralShow Me

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

Expand image参阅