DevExpress控件使用交流,DevExpress中国社区 售前咨询
当前位置: 首页 > 开发资源 » 使用教程 » 解决DevExpress XtraCharts轴标签重叠问题(代码示例)

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

作者:zhuhm   来源:本站原创   浏览:Loading...次   发布时间:2012-07-24   评论:0条

本文主要介绍两种方法来解决标签过长时导致的重叠问题。第一种方法是通过标签的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控件中文网 [http://www.devexpresscn.com/]
本文地址:http://www.devexpresscn.com/DevExpress-Resources/Documentation-165.html

评论列表

暂无评论

请谈谈你的看法 请使用IE或者Firefox浏览器,暂不支持Chrome!

昵称 不填则默认为游客评论

DevExpress DXperience DXv2 v12

DevExpress DXperience 下载 download

DevExpress购买、价格、授权

慧都控件网为DevExpress界面控件的中国地区唯一正式授权经销商,正版控件销售公司,授权代理商,经销商及合作伙伴。

电话:400-700-1020
        023-66090381

邮箱:sales@evget.com

>>如何选择正规控件购买渠道