DevExpress中chartControl中实现统计图功能

本文介绍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.youkuaiyun.com/l1158513573/article/details/46728721  DevExpress中chartControl中实现统计图功能

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值