DevExpress中chartControl中实现统计图功能

来源:互联网 发布:android ui优化 编辑:程序博客网 时间:2024/05/16 19:21

DevExpress中chartControl中实现统计图功能

以下开发均借助了DevExpress插件

首先看一下效果

首先 我们新建一个winfrom窗体 选择chartcontroll

devxpres中属性很多,有兴趣的朋友可以自己研究。

图表类型的变化 我们采用ComboBoxEdit类型的textEdit

然后我们需要对控件绑定数据以及设置图表类型

 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;         }    }


 

0 0