DevExpress中chartControl中实现统计图功能

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


 

  • 1
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
DevExpress ChartControl,可以通过以下步骤在SwiftPlot从左到右添加坐标点: 1. 设置图表的X轴类型为数值轴。 ```swift chartControl1.Diagram.SeriesDataMember = "Series"; chartControl1.Diagram.AxisX.NumericScaleOptions.AutoGrid = false; chartControl1.Diagram.AxisX.NumericScaleOptions.GridSpacing = 1; chartControl1.Diagram.AxisX.Label.ResolveOverlappingOptions.AllowRotate = false; chartControl1.Diagram.AxisX.Label.ResolveOverlappingOptions.AllowStagger = false; chartControl1.Diagram.AxisX.Label.ResolveOverlappingOptions.AllowHide = false; chartControl1.Diagram.AxisX.Label.Staggered = false; chartControl1.Diagram.AxisX.WholeRange.Auto = false; chartControl1.Diagram.AxisX.WholeRange.SideMarginsValue = 0.5; chartControl1.Diagram.AxisX.VisualRange.Auto = false; chartControl1.Diagram.AxisX.VisualRange.AutoSideMargins = false; chartControl1.Diagram.AxisX.VisualRange.SideMarginsValue = 0; chartControl1.Diagram.AxisX.VisualRange.MinValue = 0; ``` 2. 创建SwiftPlot系列并添加数据点。 ```swift SwiftPlotSeries series = new SwiftPlotSeries(); series.Points.Add(new SwiftPlotPoint(0, 10)); series.Points.Add(new SwiftPlotPoint(1, 20)); series.Points.Add(new SwiftPlotPoint(2, 30)); series.Points.Add(new SwiftPlotPoint(3, 40)); series.Points.Add(new SwiftPlotPoint(4, 50)); chartControl1.Series.Add(series); ``` 这将在SwiftPlot创建一个新的系列并添加数据点。默认情况下,SwiftPlot将从左到右自动添加数据点。如果需要,可以通过在添加数据点时指定数据点的X值来更改数据点的顺序。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值