DevExpress之ChartControl实现饼状图百分比演示实例
本文实例讲述了DevExpress中ChartControl实现饼状图百分比演示的方法。分享给大家供大家参考。具体实现方法如下:
关键代码如下:
usingSystem; usingSystem.Data; usingSystem.Windows.Forms; usingDevExpress.XtraCharts;
namespaceDevExpressChart { publicpartialclasswinPieSeriesView:Form { publicwinPieSeriesView() { InitializeComponent(); } privateDataTableCreateChartData() { DataTabletable=newDataTable("Table1"); table.Columns.Add("Name",typeof(String)); table.Columns.Add("Value",typeof(Int32)); table.Rows.Add(newobject[]{"A",10}); table.Rows.Add(newobject[]{"B",20}); table.Rows.Add(newobject[]{"C",40}); table.Rows.Add(newobject[]{"D",20}); table.Rows.Add(newobject[]{"E",30}); returntable; } privatevoidwinPieSeriesView_Load(objectsender,EventArgse) { BuilderDevChart(); } privatevoidBuilderDevChart() { Series_pieSeries=newSeries("测试",ViewType.Pie); _pieSeries.ValueDataMembers[0]="Value"; _pieSeries.ArgumentDataMember="Name"; _pieSeries.DataSource=CreateChartData(); chartControl1.Series.Add(_pieSeries); //---------------------------------------- _pieSeries.LegendPointOptions.PointView=PointView.ArgumentAndValues; _pieSeries.SetPiePercentage(); } } }
///<summary> ///饼状Series设置成百分比显示 ///</summary> ///<paramname="series">Series</param> publicstaticvoidSetPiePercentage(thisSeriesseries) { if(series.ViewisPieSeriesView) { ((PiePointOptions)series.PointOptions).PercentOptions.ValueAsPercent=true; ((PiePointOptions)series.PointOptions).ValueNumericOptions.Format=NumericFormat.Percent; ((PiePointOptions)series.PointOptions).ValueNumericOptions.Precision=0; } }