zoukankan      html  css  js  c++  java
  • DevExpress.XtraCharts.ChartControl 实例

      #region 坐标图
    
            private void CreateChart( )
            {
               DataTable  dt = CreateData();
                //Series series1 = CreateSeries("员工人数", ViewType.Line, dt, 0);
    
                #region Series
                //创建几个图形的对象
                Series series1 = CreateSeries("员工人数", ViewType.Bar, dt, 0);
                Series series2 = CreateSeries("人均月薪", ViewType.Bar, dt, 1);
                Series series3 = CreateSeries("成本TEU", ViewType.Bar, dt, 2);
                Series series4 = CreateSeries("人均生产率", ViewType.Bar, dt, 3);
                Series series5 = CreateSeries("占2005年3月人数比例", ViewType.Bar, dt, 4);
                #endregion
    
                List<Series> list = new List<Series>() { series1, series2, series3, series4, series5 };
                chartControl1.Series.AddRange(list.ToArray());
                chartControl1.Legend.Visible = false;
                chartControl1.SeriesTemplate.LabelsVisibility = DefaultBoolean.True;
    
                for (int i = 0; i < list.Count; i++)
                {
                    //list[i].View.Color = colorList[i];
    
                    CreateAxisY(list[i]);
                }
            }
    
    
            /// <summary>
            /// 根据数据创建一个图形展现
            /// </summary>
            /// <param name="caption">图形标题</param>
            /// <param name="viewType">图形类型</param>
            /// <param name="dt">数据DataTable</param>
            /// <param name="rowIndex">图形数据的行序号</param>
            /// <returns></returns>
            private Series CreateSeries(string caption, ViewType viewType, DataTable dt, int rowIndex)
            {
                Series series = new Series(caption, viewType);
                for (int i = 1; i < dt.Columns.Count; i++)
                {
                    string argument = dt.Columns[i].ColumnName;//参数名称
                    decimal value = (decimal)dt.Rows[rowIndex][i];//参数值
                    series.Points.Add(new SeriesPoint(argument, value));
                }
    
                //必须设置ArgumentScaleType的类型,否则显示会转换为日期格式,导致不是希望的格式显示
                //也就是说,显示字符串的参数,必须设置类型为ScaleType.Qualitative
                series.ArgumentScaleType = ScaleType.Qualitative;
                series.LabelsVisibility = DevExpress.Utils.DefaultBoolean.True;//显示标注标签
    
                return series;
            }
    
            /// <summary>
            /// 准备数据内容
            /// </summary>
            /// <returns></returns>
            private DataTable CreateData()
            {
                DataTable dt = new DataTable();
                dt.Columns.Add(new DataColumn("类型"));
                dt.Columns.Add(new DataColumn("2005-1月", typeof(decimal)));
                dt.Columns.Add(new DataColumn("2005-2月", typeof(decimal)));
                dt.Columns.Add(new DataColumn("2005-3月", typeof(decimal)));
                dt.Columns.Add(new DataColumn("2005-4月", typeof(decimal)));
                dt.Columns.Add(new DataColumn("2005-5月", typeof(decimal)));
                dt.Columns.Add(new DataColumn("2005-6月", typeof(decimal)));
    
                dt.Rows.Add(new object[] { "员工人数", 437, 437, 414, 397, 387, 378 });
                dt.Rows.Add(new object[] { "人均月薪", 3964, 3961, 3979, 3974, 3967, 3972 });
                dt.Rows.Add(new object[] { "成本TEU", 3104, 1339, 3595.8, 3154.5, 2499.8, 3026 });
                dt.Rows.Add(new object[] { "人均生产率", 7.1, 3.06, 8.69, 7.95, 6.46, 8.01 });
                dt.Rows.Add(new object[] { "占2005年3月人数比例", 1.06, 1.06, 1, 0.96, 0.93, 0.91 });
    
                return dt;
            }
    
            /// <summary>
            /// 创建图表的第二坐标系
            /// </summary>
            /// <param name="series">Series对象</param>
            /// <returns></returns>
            private SecondaryAxisY CreateAxisY(Series series)
            {
                SecondaryAxisY myAxis = new SecondaryAxisY(series.Name);
                ((XYDiagram)chartControl1.Diagram).SecondaryAxesY.Add(myAxis);
                ((BarSeriesView)series.View).AxisY = myAxis;   
                //LineSeriesView
                myAxis.Title.Text = series.Name;
                myAxis.Title.Alignment = StringAlignment.Far; //顶部对齐
                myAxis.Title.Visible = true; //显示标题
                myAxis.Title.Font = new Font("宋体", 9.0f);
    
                Color color = series.View.Color;//设置坐标的颜色和图表线条颜色一致
    
                myAxis.Title.TextColor = color;
                myAxis.Label.TextColor = color;
                myAxis.Color = color;
    
                return myAxis;
            }
    
            /// <summary>
            /// 创建图表的第二坐标系
            /// </summary>
            /// <param name="series">Series对象</param>
            /// <returns></returns>
            private SecondaryAxisX CreateAxisX(Series series)
            {
                SecondaryAxisX myAxis = new SecondaryAxisX(series.Name);
                ((XYDiagram)chartControl1.Diagram).SecondaryAxesX.Add(myAxis);
                ((LineSeriesView)series.View).AxisX = myAxis;
                myAxis.Title.Text = series.Name;
                myAxis.Title.Alignment = StringAlignment.Far; //顶部对齐
                myAxis.Title.Visible = true; //显示标题
                myAxis.Title.Font = new Font("宋体", 9.0f);
    
                Color color = series.View.Color;//设置坐标的颜色和图表线条颜色一致
    
                myAxis.Title.TextColor = color;
                myAxis.Label.TextColor = color;
                myAxis.Color = color;
    
                return myAxis;
            }
            #endregion
    

      DevExpress.XtraCharts.ChartControl 

  • 相关阅读:
    写给大忙人的spring cloud 1.x学习指南
    spring boot 1.x完整学习指南(含各种常见问题servlet、web.xml、maven打包,spring mvc差别及解决方法)
    Spring-Data-Redis下实现redis连接断开后自动重连(真正解决)
    写给大忙人的nginx核心配置详解(匹配&重写、集群、环境变量&上下文、Lua)
    javax.validation.UnexpectedTypeException: HV000030: No validator could be found for constraint 解决方法
    linux下配置nginx使用ftp目录作为静态资源文件的目标目录
    写给大忙人的centos下ftp服务器搭建(以及启动失败/XFTP客户端一直提示“用户身份验证失败”解决方法)
    linux下mysql 8.0安装
    写给大忙人的Elasticsearch架构与概念(未完待续)
    写给大忙人的ELK最新版6.2.4学习笔记-Logstash和Filebeat解析(java异常堆栈下多行日志配置支持)
  • 原文地址:https://www.cnblogs.com/lhlong/p/6030848.html
Copyright © 2011-2022 走看看