DevExpress中chartControl中实现统计图功能

 public partial class Form1 : DevExpress.XtraEditors.XtraForm
    {
        public Form1()
        {
            InitializeComponent();
            LoadAll();
        }
        public void LoadAll()
        {   //Series  对象表示数据系列,并且存储在 SeriesCollection 类中。
            Series s1 = this.chartControl1.Series[0];//新建一个series类并给控件赋值
            s1.DataSource = ServiceData.GetClassCount();//设置实例对象s1的数据源
            s1.ArgumentDataMember = "class";//绑定图表的横坐标
            s1.ValueDataMembers[0] = "count"; //绑定图表的纵坐标坐标
            s1.LegendText = "人数";//设置图例文字 就是右上方的小框框               
        }
        private void textEdit1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (this.textEdit1.Text == "--请选择图表类型--")return;

            if (this.textEdit1.Text == "漏斗图")
            {
                DevExpress.XtraCharts.FunnelSeriesView funnelSeriesView1 = new DevExpress.XtraCharts.FunnelSeriesView();
                this.chartControl1.Series[0].View = funnelSeriesView1;
            }
            if (this.textEdit1.Text == "折线图")
            {
                DevExpress.XtraCharts.LineSeriesView lineSeriesView1 = new DevExpress.XtraCharts.LineSeriesView();
                this.chartControl1.Series[0].View = lineSeriesView1;
            }
            if (this.textEdit1.Text == "饼状图")
            {
                DevExpress.XtraCharts.PieSeriesView pieSeriesView1 = new DevExpress.XtraCharts.PieSeriesView();
                this.chartControl1.Series[0].View = pieSeriesView1;
            }
            if (this.textEdit1.Text == "柱形图")
            {
                DevExpress.XtraCharts.StackedBarSeriesView stackedBarSeriesView1 = new DevExpress.XtraCharts.StackedBarSeriesView();
                this.chartControl1.Series[0].View = stackedBarSeriesView1;
            } 
        }
    }
    //创建测试数据表
    public static class ServiceData
   {
        public static DataTable GetClassCount()
         {
            DataTable dt = new DataTable();
            dt.Columns.Add("class", typeof(string));//年级
            dt.Columns.Add("count", typeof(int));   //人数
            dt.Rows.Add("一年级", 120);
            dt.Rows.Add("二年级", 180);
            dt.Rows.Add("三年级", 890);
            dt.Rows.Add("四年级", 108);
            dt.Rows.Add("五年级", 280);
            dt.Rows.Add("六年级", 320);
            dt.Rows.Add("七年级", 450);
            dt.Rows.Add("八年级", 410);
            dt.Rows.Add("九年级", 230);
            return dt; 
        }
    }

源文: http://blog.csdn.net/l1158513573/article/details/46728721  DevExpress中chartControl中实现统计图功能

原文地址:https://www.cnblogs.com/shy1766IT/p/7568539.html