DevExpress ChartControl 饼状图演示,显示百分比和项目名称
作者:C/S框架网  发布日期:2017-01-07 11:58:57
  DevExpress ChartControl 饼状图演示,显示百分比和项目名称

DevExpress ChartControl 饼状图演示,显示百分比和项目名称。


C# Code:


public partial class frmPie : Form
{
   public frmPie()
   {
      InitializeComponent();
   }
   
   private void Form2_Load(object sender, EventArgs e)
   {
      DataTable dt = CreateData();
      CreateChart(dt);
   }
   
   private DataTable CreateData()
   {
      DataTable dt = new DataTable();
      dt.Columns.Add(new DataColumn("ItemName")); //项目名称
      dt.Columns.Add(new DataColumn("ItemValue", typeof(decimal))); //取值字段
      
      dt.Rows.Add(new object[] { "张志雨", 4200000 });
      dt.Rows.Add(new object[] { "郑兴玉", 2880000 });
      dt.Rows.Add(new object[] { "王付成", 1323104 });
      dt.Rows.Add(new object[] { "张佳慧", 1680000 });
      dt.Rows.Add(new object[] { "曹操", 3100000 });
      
      return dt;
   }
   
   private void CreateChart(DataTable dt)
   {
      chartControl1.Series.Clear();
      
      Series series = new Series("2016-12月销售对表", ViewType.Pie);
      series.DataSource = dt;
      series.ArgumentScaleType = ScaleType.Qualitative;
      
      //项目名称
      series.ArgumentDataMember = "ItemName";
      series.ValueScaleType = ScaleType.Numerical;
      
      //取值字段
      series.ValueDataMembers.AddRange(new string[] { "ItemValue" });
      (series.Label as PieSeriesLabel).Position = PieSeriesLabelPosition.Inside;
      
      //显示百分比和项目名称(业务员姓名)
      series.PointOptions.PointView = PointView.ArgumentAndValues;
      series.PointOptions.ValueNumericOptions.Format = NumericFormat.Percent;
      
      this.chartControl1.Series.Add(series);
      
      //右上角分组视图
      this.chartControl1.Legend.MarkerSize = new System.Drawing.Size(20, 20);
      this.chartControl1.Legend.TextOffset = 5;
      this.chartControl1.Legend.VerticalIndent = 5;
      this.chartControl1.Legend.Border.Color = Color.Red;//红色边框
   }
   
   private void checkEdit1_CheckedChanged_1(object sender, EventArgs e)
   {
      foreach (Series S in chartControl1.Series)
      S.LabelsVisibility = checkEdit1.Checked ? DevExpress.Utils.DefaultBoolean.True : DevExpress.Utils.DefaultBoolean.False;//显示标注标签
   }
}

//来源:C/S框架网(www.csframework.com) QQ:1980854898




贴图图片
上一篇 下一篇