博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ChartControl实现时间轴实现
阅读量:6280 次
发布时间:2019-06-22

本文共 6951 字,大约阅读时间需要 23 分钟。

using System;using System.Data;using System.Windows.Forms;using DevExpress.XtraCharts;namespace DevExpressChart{    public partial class winDateTime : Form    {        public winDateTime()        {            InitializeComponent();        }        private void winDateTime_Load(object sender, EventArgs e)        {            BuilderDevChart();        }        private DataTable CreateChartData()        {            DataTable table = new DataTable("Table1");            table.Columns.Add("Date", typeof(DateTime));            table.Columns.Add("Value", typeof(Int32));            table.Rows.Add(new object[] { new DateTime(2014, 5, 21), 10 });            table.Rows.Add(new object[] { new DateTime(2014, 6, 22), 20 });            table.Rows.Add(new object[] { new DateTime(2014, 7, 23), 40 });            table.Rows.Add(new object[] { new DateTime(2014, 8, 24), 20 });            table.Rows.Add(new object[] { new DateTime(2014, 9, 25), 30 });            return table;        }        private void BuilderDevChart()        {            Series _lineSeries = new Series("利润", ViewType.Line);            _lineSeries.ArgumentScaleType = ScaleType.DateTime;            _lineSeries.ArgumentDataMember = "Date";            _lineSeries.ValueDataMembers[0] = "Value";            _lineSeries.DataSource = CreateChartData();            chartControl1.Series.Add(_lineSeries);            chartControl1.SetTimeAxisX(DateTimeMeasurementUnit.Month, DateTimeMeasurementUnit.Month, "yyyy-MM");            //---------------------------------------------------------------            //_lineSeries.ValueScaleType = ScaleType.DateTime;            //_lineSeries.ArgumentDataMember = "Value";            //_lineSeries.ValueDataMembers[0] = "Date";            //_lineSeries.DataSource = CreateChartData();            //chartControl1.Series.Add(_lineSeries);             //XYDiagram _diagram = (XYDiagram)chartControl1.Diagram;            //_diagram.AxisY.DateTimeMeasureUnit = DateTimeMeasurementUnit.Month;            //_diagram.AxisY.DateTimeGridAlignment = DateTimeMeasurementUnit.Month;            //_diagram.AxisY.DateTimeOptions.Format = DateTimeFormat.Custom;            //_diagram.AxisY.DateTimeOptions.FormatString = "MMMM";        }    }}
using DevExpress.Utils;using DevExpress.XtraCharts;namespace DevExpressChart{    public static class ChartUtils    {        ///         /// 增加数据筛选        ///         /// Series        /// 列名称        /// 列名称对应的筛选数值        /// DataFilterCondition枚举        public static void AddDataFilter(this SeriesBase series, string columnName, object value, DataFilterCondition dataFilterCondition)        {            series.DataFilters.Add(new DataFilter(columnName, value.GetType().FullName, dataFilterCondition, value));        }        ///         /// 设置X轴Lable角度        ///         /// ChartControl        /// 角度        public static void SetXLableAngle(this ChartControl chart, int angle)        {            XYDiagram _xyDiagram = (XYDiagram)chart.Diagram;            if (_xyDiagram != null)                _xyDiagram.AxisX.Label.Angle = angle;        }        ///         ///  设置Y轴Lable角度        ///         /// ChartControl        /// 角度        public static void SetYLableAngle(this ChartControl chart, int angle)        {            XYDiagram _xyDiagram = (XYDiagram)chart.Diagram;            _xyDiagram.AxisY.Label.Angle = angle;        }        ///         /// 设置ColorEach        ///         /// ChartControl        /// 是否设置成ColorEach        public static void SetColorEach(this Series series, bool colorEach)        {            SeriesViewColorEachSupportBase colorEachView = (SeriesViewColorEachSupportBase)series.View;            if (colorEachView != null)            {                colorEachView.ColorEach = colorEach;            }        }        ///         /// 设置是否显示十字标线        ///         /// ChartControl        /// 是否显示十字标线        public static void SetCrosshair(this ChartControl chart, bool crosshair)        {            chart.CrosshairEnabled = crosshair ? DefaultBoolean.True : DefaultBoolean.False;            chart.CrosshairOptions.ShowArgumentLabels = crosshair;            chart.CrosshairOptions.ShowArgumentLine = crosshair;            chart.CrosshairOptions.ShowValueLabels = crosshair;            chart.CrosshairOptions.ShowValueLine = crosshair;        }        ///         /// 新增ChartControl的Title文字        ///         /// ChartControl        /// Title文字        public static void AddTitle(this ChartControl chart, string title)        {            ChartTitle _title = new ChartTitle();            _title.Text = title;            chart.Titles.Add(_title);        }        ///         /// 饼状Series设置成百分比显示        ///         /// Series        public static void SetPiePercentage(this Series series)        {            if (series.View is PieSeriesView)            {                ((PiePointOptions)series.PointOptions).PercentOptions.ValueAsPercent = true;                ((PiePointOptions)series.PointOptions).ValueNumericOptions.Format = NumericFormat.Percent;                ((PiePointOptions)series.PointOptions).ValueNumericOptions.Precision = 0;            }        }        ///         /// 将X轴格式化成时间轴        ///         /// ChartControl        /// X轴刻度单位        /// X轴刻度间距的单位        public static void SetTimeAxisX(this ChartControl chart, DateTimeMeasurementUnit dateTimeMeasureUnit, DateTimeMeasurementUnit dateTimeGridAlignment)        {            XYDiagram _diagram = (XYDiagram)chart.Diagram;            if (_diagram != null)            {                           _diagram.AxisX.DateTimeMeasureUnit = DateTimeMeasurementUnit.Month;//X轴刻度单位                _diagram.AxisX.DateTimeGridAlignment = DateTimeMeasurementUnit.Month;//X轴刻度间距            }        }        ///         /// 将X轴格式化成时间轴        ///         /// ChartControl        /// X轴刻度单位        /// X轴刻度间距的单位        /// 时间格式;eg:yyyy-MM        public static void SetTimeAxisX(this ChartControl chart, DateTimeMeasurementUnit dateTimeMeasureUnit, DateTimeMeasurementUnit dateTimeGridAlignment, string formatString)        {            XYDiagram _diagram = (XYDiagram)chart.Diagram;            if (_diagram != null)            {                _diagram.AxisX.DateTimeMeasureUnit = DateTimeMeasurementUnit.Month;//X轴刻度单位                _diagram.AxisX.DateTimeGridAlignment = DateTimeMeasurementUnit.Month;//X轴刻度间距                _diagram.AxisX.DateTimeOptions.Format = DateTimeFormat.Custom;                _diagram.AxisX.DateTimeOptions.FormatString = formatString;            }        }    }}

运行效果如下图所示:

 

DevExpress ChartControl加载大数据量数据时的性能优化方法有哪些?

关于图表优化,可从以下几个方面解决:

1.关闭不需要的可视化的元素(如LineMarkers, Labels等): Series.View.LineMarkerOptions.Visible =false.

2. 关闭图表的滚动与缩放功能,手动调整范围,这样将大大减少所需计算的个数。

3. 将 ChartControl.RefreshDataOnRepaint属性设为false

4. 将 ChartControl.CacheToMemory属性设为true,这样将通过缓存提供图表性能及内存消耗。

5. 将ChartControl.RuntimeHitTesting属性设为false。这样将禁用聚焦检查及测试,提供图表重绘速度.

转载于:https://www.cnblogs.com/MuNet/archive/2013/04/05/5736027.html

你可能感兴趣的文章
配置Quartz
查看>>
Linux 线程实现机制分析
查看>>
继承自ActionBarActivity的activity的activity theme问题
查看>>
设计模式01:简单工厂模式
查看>>
项目经理笔记一
查看>>
Hibernate一对一外键双向关联
查看>>
mac pro 入手,php环境配置总结
查看>>
MyBatis-Plus | 最简单的查询操作教程(Lambda)
查看>>
rpmfusion 的国内大学 NEU 源配置
查看>>
spring jpa 配置详解
查看>>
IOE,为什么去IOE?
查看>>
java 用反射简单应用,将Object简单转换成map
查看>>
Storm中的Worker
查看>>
dangdang.ddframe.job中页面修改表达式后进行检查
查看>>
Web基础架构:负载均衡和LVS
查看>>
Linux下c/c++相对路径动态库的生成与使用
查看>>
SHELL实现跳板机,只允许用户执行少量允许的命令
查看>>
SpringBoot 整合Redis
查看>>
2014上半年大片早知道
查看>>
Android 6.0指纹识别App开发案例
查看>>