简要说明
饼图 是由 PieSeriesView 对象来表示的,此对象属于 饼、圆环和漏斗系列视图。 当需要比较相同系列中不同点参数的百分比取值、并且以易于理解的饼切块说明这些取值时,这种视图是有用的。
在下面的插图中显示了一个饼图。 注意,如果图表包含多个 PieSeriesView 类型的系列,那么就根据 SimpleDiagram.Dimension 和 SimpleDiagram.LayoutDirection 属性值,在相同的图象中显示所有这些系列。
图表类型特征
下表列出了这种图表类型的主要特征。
特征 |
取值 |
---|---|
系列视图类型 | PieSeriesView |
图象类型 | 2D- SimpleDiagram |
每个数据点的参数个数 | 1 |
每个数据点的取值个数 | 1 |
注意 |
---|
要获得关于哪些图表类型可以与 饼图 组合使用的信息,请参阅 组合使用不同的系列视图 文档。 |
示例
下面的示例演示了在运行时刻如何创建 ChartControl (拥有一个 PieSeriesView 类型的系列),并把图表添加到窗体中。 在继续本示例之前,首先要在 Visual Studio 中创建一个 Windows 窗体应用程序,并把所有 必需的程序集 包含到项目的“引用”列表中。
然后,把下列代码添加到 Form.Load 事件处理程序。
C# | 复制代码 |
---|---|
using DevExpress.XtraCharts; // ... private void Form1_Load(object sender, EventArgs e) { // Create an empty chart. ChartControl pieChart = new ChartControl(); // Create a pie series. Series series1 = new Series("A Pie Series", ViewType.Pie); // Populate the series with points. series1.Points.Add(new SeriesPoint("Russia", 17.0752)); series1.Points.Add(new SeriesPoint("Canada", 9.98467)); series1.Points.Add(new SeriesPoint("USA", 9.63142)); series1.Points.Add(new SeriesPoint("China", 9.59696)); series1.Points.Add(new SeriesPoint("Brazil", 8.511965)); series1.Points.Add(new SeriesPoint("Australia", 7.68685)); series1.Points.Add(new SeriesPoint("India", 3.28759)); series1.Points.Add(new SeriesPoint("Others", 81.2)); // Add the series to the chart. pieChart.Series.Add(series1); // Adjust the point options of the series. series1.PointOptions.PointView = PointView.ArgumentAndValues; series1.PointOptions.ValueNumericOptions.Format = NumericFormat.Percent; series1.PointOptions.ValueNumericOptions.Precision = 0; // Detect overlapping of series labels. ((PieSeriesLabel)series1.Label).ResolveOverlappingMode = ResolveOverlappingMode.Default; // Access the view-type-specific options of the series. PieSeriesView myView = (PieSeriesView)series1.View; // Show a title for the series. myView.Titles.Add(new SeriesTitle()); myView.Titles[0].Text = series1.Name; // Specify a data filter to explode points. myView.ExplodedPointsFilters.Add(new SeriesPointFilter(SeriesPointKey.Value_1, DataFilterCondition.GreaterThanOrEqual, 9)); myView.ExplodedPointsFilters.Add(new SeriesPointFilter(SeriesPointKey.Argument, DataFilterCondition.NotEqual, "Others")); myView.ExplodeMode = PieExplodeMode.UseFilters; myView.ExplodedDistancePercentage = 30; myView.RuntimeExploding = true; myView.HeightToWidthRatio = 99; // Hide the legend (if necessary). pieChart.Legend.Visible = false; // Add the chart to the form. pieChart.Dock = DockStyle.Fill; this.Controls.Add(pieChart); } |
Visual Basic | 复制代码 |
---|---|
Imports DevExpress.XtraCharts ' ... Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _ Handles MyBase.Load ' Create an empty chart. Dim pieChart As New ChartControl() ' Create a pie series. Dim series1 As New Series("A Pie Series", ViewType.Pie) ' Populate the series with points. series1.Points.Add(New SeriesPoint("Russia", 17.0752)) series1.Points.Add(New SeriesPoint("Canada", 9.98467)) series1.Points.Add(New SeriesPoint("USA", 9.63142)) series1.Points.Add(New SeriesPoint("China", 9.59696)) series1.Points.Add(New SeriesPoint("Brazil", 8.511965)) series1.Points.Add(New SeriesPoint("Australia", 7.68685)) series1.Points.Add(New SeriesPoint("India", 3.28759)) series1.Points.Add(New SeriesPoint("Others", 81.2)) ' Add the series to the chart. pieChart.Series.Add(series1) ' Adjust the point options of the series. series1.PointOptions.PointView = PointView.ArgumentAndValues series1.PointOptions.ValueNumericOptions.Format = NumericFormat.Percent series1.PointOptions.ValueNumericOptions.Precision = 0 ' Detect overlapping of series labels. CType(series1.Label, PieSeriesLabel).ResolveOverlappingMode = _ ResolveOverlappingMode.Default ' Access the view-type-specific options of the series. Dim myView As PieSeriesView = CType(series1.View, PieSeriesView) ' Show a title for the series. myView.Titles.Add(New SeriesTitle()) myView.Titles(0).Text = series1.Name ' Specify a data filter to explode points. myView.ExplodedPointsFilters.Add(New SeriesPointFilter _ (SeriesPointKey.Value_1, DataFilterCondition.GreaterThanOrEqual, 9)) myView.ExplodedPointsFilters.Add(New SeriesPointFilter _ (SeriesPointKey.Argument, DataFilterCondition.NotEqual, "Others")) myView.ExplodeMode = PieExplodeMode.UseFilters myView.ExplodedDistancePercentage = 30 myView.RuntimeExploding = True myView.HeightToWidthRatio = 99 ' Hide the legend (if necessary). pieChart.Legend.Visible = False ' Add the chart to the form. pieChart.Dock = DockStyle.Fill Me.Controls.Add(pieChart) End Sub |
Show Me |
---|
在 DevExpress Code Central 数据库中可以找到完整的示例项目,网址是 http://www.devexpress.com/example=E1189。 取决于目标平台类型 (ASP.NET、WinForms 等),可以在线运行本示例,或者下载自动可执行的示例。 |