本示例演示了消除 轴标签 重叠的两种方式: 错开轴标签 (以 Z 字型显示),或者以某种角度倾斜轴标签 (对文本修边)。

C#CopyCode image复制代码
using System;
using System.Windows.Forms;
using DevExpress.XtraCharts;
// ...

private void Form1_Load(object sender, EventArgs e) {
    // Create an empty chart.
    ChartControl chartControl1 = new ChartControl();

    // Create a series and add points to it.
    Series series1 = new Series("Series 1", ViewType.Bar);

    series1.Points.Add(new SeriesPoint("First Argument", 10.5678));
    series1.Points.Add(new SeriesPoint("Second Argument", 12.5798));
    series1.Points.Add(new SeriesPoint("Third Argument", 11.6483));
    series1.Points.Add(new SeriesPoint("Fourth Argument", 12.3154));
    series1.Points.Add(new SeriesPoint("Fifth Argument", 12.7865));

    // Add the series to the chart.
    chartControl1.Series.Add(series1);

    // Hide the legend (optional).
    chartControl1.Legend.Visible = false;
    
    // Cast the chart's diagram to the XYDiagram type,
    // to access its axes.
    XYDiagram diagram = (XYDiagram)chartControl1.Diagram;

    // Make the X-axis labels staggered.
    diagram.AxisX.Label.Staggered = true;

    // Add a prefix to the Y-axis labels, and rotate them.
    diagram.AxisY.Label.BeginText = "Axis value = ";
    diagram.AxisY.Label.Angle = -30;
    diagram.AxisY.Label.Antialiasing = true;
    
    // Add the chart to the form.
    chartControl1.Dock = DockStyle.Fill;
    this.Controls.Add(chartControl1);
}
Visual BasicCopyCode image复制代码
Imports System
Imports System.Windows.Forms
Imports DevExpress.XtraCharts
' ...

Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
    ' Create an empty chart.
    Dim chartControl1 As New ChartControl()

    ' Create a series and add points to it.
    Dim series1 As New Series("Series 1", ViewType.Bar)

    series1.Points.Add(New SeriesPoint("First Argument", 10.5678))
    series1.Points.Add(New SeriesPoint("Second Argument", 12.5798))
    series1.Points.Add(New SeriesPoint("Third Argument", 11.6483))
    series1.Points.Add(New SeriesPoint("Fourth Argument", 12.3154))
    series1.Points.Add(New SeriesPoint("Fifth Argument", 12.7865))

    ' Add the series to the chart.
    chartControl1.Series.Add(series1)

    ' Hide the legend (optional).
    chartControl1.Legend.Visible = False

    ' Cast the chart's diagram to the XYDiagram type,
    ' to access its axes.
    Dim diagram As XYDiagram = CType(chartControl1.Diagram, XYDiagram)

    ' Make the X-axis labels staggered.
    diagram.AxisX.Label.Staggered = True

    ' Add a prefix to the Y-axis labels, and rotate them.
    diagram.AxisY.Label.BeginText = "Axis value = "
    diagram.AxisY.Label.Angle = -30
    diagram.AxisY.Label.Antialiasing = True

    ' Add the chart to the form.
    chartControl1.Dock = DockStyle.Fill
    Me.Controls.Add(chartControl1)
End Sub

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

CodeCentralShow Me

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

Expand image参阅