首页 > 代码库 > [DevExpress]ChartControl之饼状图百分比演示

[DevExpress]ChartControl之饼状图百分比演示

关键代码:

using System;using System.Data;using System.Windows.Forms;using DevExpress.XtraCharts;namespace DevExpressChart{    public partial class winPieSeriesView : Form    {        public winPieSeriesView()        {            InitializeComponent();        }        private DataTable CreateChartData()        {            DataTable table = new DataTable("Table1");            table.Columns.Add("Name", typeof(String));            table.Columns.Add("Value", typeof(Int32));             table.Rows.Add(new object[] { "A", 10 });            table.Rows.Add(new object[] { "B", 20 });            table.Rows.Add(new object[] { "C", 40 });            table.Rows.Add(new object[] { "D", 20 });            table.Rows.Add(new object[] { "E", 30 });            return table;        }        private void winPieSeriesView_Load(object sender, EventArgs e)        {            BuilderDevChart();        }        private void BuilderDevChart()        {            Series _pieSeries = new Series("测试", ViewType.Pie);            _pieSeries.ValueDataMembers[0] = "Value";            _pieSeries.ArgumentDataMember = "Name";            _pieSeries.DataSource = CreateChartData();            chartControl1.Series.Add(_pieSeries);            //----------------------------------------            _pieSeries.LegendPointOptions.PointView = PointView.ArgumentAndValues;            _pieSeries.SetPiePercentage();        }    }}

<style type="text/css">.csharpcode, .csharpcode pre{ font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/}.csharpcode pre { margin: 0em; }.csharpcode .rem { color: #008000; }.csharpcode .kwrd { color: #0000ff; }.csharpcode .str { color: #006080; }.csharpcode .op { color: #0000c0; }.csharpcode .preproc { color: #cc6633; }.csharpcode .asp { background-color: #ffff00; }.csharpcode .html { color: #800000; }.csharpcode .attr { color: #ff0000; }.csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em;}.csharpcode .lnum { color: #606060; }</style>---------------------------------------------------------------------------------------------

        /// <summary>        /// 饼状Series设置成百分比显示        /// </summary>        /// <param name="series">Series</param>        public static void SetPiePercentage(this Series series)        {            if (series.View is PieSeriesView)            {                ((PiePointOptions)series.PointOptions).PercentOptions.ValueAsPercent = true;                ((PiePointOptions)series.PointOptions).ValueNumericOptions.Format = NumericFormat.Percent;                ((PiePointOptions)series.PointOptions).ValueNumericOptions.Precision = 0;            }        }

运行效果:

image

希望有所帮助!谢谢!微笑

<style type="text/css">.csharpcode, .csharpcode pre{ font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/}.csharpcode pre { margin: 0em; }.csharpcode .rem { color: #008000; }.csharpcode .kwrd { color: #0000ff; }.csharpcode .str { color: #006080; }.csharpcode .op { color: #0000c0; }.csharpcode .preproc { color: #cc6633; }.csharpcode .asp { background-color: #ffff00; }.csharpcode .html { color: #800000; }.csharpcode .attr { color: #ff0000; }.csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em;}.csharpcode .lnum { color: #606060; }</style>

[DevExpress]ChartControl之饼状图百分比演示