2024年终活动

DevExpress控件使用交流,DevExpress中国社区Dev联系电话 联系电话:023-68661681

解决DevExpress XtraCharts轴标签重叠问题(代码示例)

来源:本站原创   发布时间:2012-07-24   浏览:4719次

本文主要介绍两种方法来解决标签过长时导致的重叠问题。第一种方法是通过标签的Angle属性将标签旋转。此外,我们建立您启用Antialiasing属性,有助于流畅地绘制标签文本。第二种方法是使用轴标签的Staggered属性。

注:从DXperience12.1开始,已经解决XtraCharts轴标签的重叠问题。

C#

using System;
using System.Windows.Forms;
using DevExpress.XtraCharts;
// ...

namespace AxisLabelsResolveOverlapping {
public partial class Form1: Form {
public Form1() {
InitializeComponent();
}

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);
}

}
}

VB.NET

Imports Microsoft.VisualBasic
Imports System
Imports System.Windows.Forms
Imports DevExpress.XtraCharts
' ...

Namespace AxisLabelsResolveOverlapping
Partial Public Class Form1
Inherits Form
Public Sub New()
InitializeComponent()
End Sub

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

End Class
End Namespace

本站文章除注明转载外,均为本站原创或翻译
欢迎任何形式的转载,但请务必注明出处,尊重他人劳动成果
转载请注明:文章转载自:DevExpress控件中文网 [https://www.devexpresscn.com/]
本文地址:https://www.devexpresscn.com/post/265.html
扫码咨询
电话咨询
023-68661681
返回
顶部