[DevExpress]ChartControl之时间轴示例

关键代码:

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

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }-------------------------------------------------------------------------------------

using DevExpress.Utils;
using DevExpress.XtraCharts;

namespace DevExpressChart
{
    public static class ChartUtils
    {
        /// <summary>
        /// 增加数据筛选
        /// </summary>
        /// <param name="SeriesBase">Series</param>
        /// <param name="columnName">列名称</param>
        /// <param name="value">列名称对应的筛选数值</param>
        /// <param name="dataFilterCondition">DataFilterCondition枚举</param>
        public static void AddDataFilter(this SeriesBase series, string columnName, object value, DataFilterCondition dataFilterCondition)
        {
            series.DataFilters.Add(new DataFilter(columnName, value.GetType().FullName, dataFilterCondition, value));
        }

        /// <summary>
        /// 设置X轴Lable角度
        /// </summary>
        /// <param name="chart">ChartControl</param>
        /// <param name="angle">角度</param>
        public static void SetXLableAngle(this ChartControl chart, int angle)
        {
            XYDiagram _xyDiagram = (XYDiagram)chart.Diagram;
            if (_xyDiagram != null)
                _xyDiagram.AxisX.Label.Angle = angle;
        }
        /// <summary>
        ///  设置Y轴Lable角度
        /// </summary>
        /// <param name="chart">ChartControl</param>
        /// <param name="angle">角度</param>
        public static void SetYLableAngle(this ChartControl chart, int angle)
        {
            XYDiagram _xyDiagram = (XYDiagram)chart.Diagram;
            _xyDiagram.AxisY.Label.Angle = angle;
        }
        /// <summary>
        /// 设置ColorEach
        /// </summary>
        /// <param name="chart">ChartControl</param>
        /// <param name="colorEach">是否设置成ColorEach</param>
        public static void SetColorEach(this Series series, bool colorEach)
        {
            SeriesViewColorEachSupportBase colorEachView = (SeriesViewColorEachSupportBase)series.View;
            if (colorEachView != null)
            {
                colorEachView.ColorEach = colorEach;
            }
        }
        /// <summary>
        /// 设置是否显示十字标线
        /// </summary>
        /// <param name="chart">ChartControl</param>
        /// <param name="crosshair">是否显示十字标线</param>
        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;
        }
        /// <summary>
        /// 新增ChartControl的Title文字
        /// </summary>
        /// <param name="chart">ChartControl</param>
        /// <param name="title">Title文字</param>
        public static void AddTitle(this ChartControl chart, string title)
        {
            ChartTitle _title = new ChartTitle();
            _title.Text = title;
            chart.Titles.Add(_title);
        }
        /// <summary>
        /// 饼状Series设置成百分比显示
        /// </summary>
        /// <param name="series">Series</param>
        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;
            }
        }
        /// <summary>
        /// 将X轴格式化成时间轴
        /// </summary>
        /// <param name="chart">ChartControl</param>
        /// <param name="dateTimeMeasureUnit">X轴刻度单位</param>
        /// <param name="dateTimeGridAlignment">X轴刻度间距的单位</param>
        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轴刻度间距
            }
        }
        /// <summary>
        /// 将X轴格式化成时间轴
        /// </summary>
        /// <param name="chart">ChartControl</param>
        /// <param name="dateTimeMeasureUnit">X轴刻度单位</param>
        /// <param name="dateTimeGridAlignment">X轴刻度间距的单位</param>
        /// <param name="formatString">时间格式;eg:yyyy-MM</param>
        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;
            }
        }
    }
}

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }运行效果:

希望有所帮助!谢谢

时间: 2024-10-13 12:35:48

[DevExpress]ChartControl之时间轴示例的相关文章

DevExpress之ChartControl实现时间轴实例 z

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 sende

[DevExpress]ChartControl之自定义Tooltip示例

关键代码: /// <summary> /// 自定义ChartControl的Tooltip /// </summary> /// <param name="chart">ChartControl</param> /// <param name="e">MouseEventArgs</param> /// <param name="tooltip">ToolTi

[DevExpress]ChartControl之创建Strip示例

关键代码: /// <summary> /// 创建Strip /// </summary> /// <param name="chart">ChartControl</param> /// <param name="strip">Strip</param> /// <param name="stripLable">Strip文字</param> //

【原】为DevExpress的ChartControl添加Y轴控制 和 GridControl中指定列添加超级链接

一.控制ChartControl的Y轴范围 使用Devexpress中的CharControl控件,需要控制AxisY轴的显示范围,需要使用该控件的BoundDataChanged事件,具体代码如下: 该代码实现的效果如下:   二.设置GridControl表格中的超级链接: 1.首先在表格的设计器中添加一个HyperLinkEdit 的 Repository: 2.将该Repository绑定到列表中的指定列中: 3.为第一步添加的rpLink控件添加Open_Link事件处理函数: 4.最

Devexpress WPF ChartControl 多Y轴

<Window x:Class="DXApplication4.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:dxc="http://schemas.devexpress.com/winfx/2008/

jQuery时间轴插件:jQuery Timelinr

前言 这是一款可用于展示历史和计划的时间轴插件,尤其比较适合一些网站展示发展历程.大事件等场景.该插件基于jQuery,可以滑动切换.水平和垂直滚动.支持键盘方向键.经过扩展后可以支持鼠标滚轮事件. HTML 我们在body中建立一个div#timeline作为展示区,#dates为时间轴,示例中我们用年份作为主轴,#issues作为内容展示区,即展示对应主轴点年份的内容,注意id对应上. <div id="timeline"> <ul id="dates&

DevExpress XtraGrid网格控件示例六:自定义合并单元格

假设 "Order Date" 列中包含日期/时间值.如果视图的GridOptionsView.AllowCellMerge选项设置为true,若相邻两个单元格值是日期/时间值的话,这两个相邻单元格便会合并.下面的代码介绍了如何合并例单元格的日期部分,要覆盖默认的单元格合并机制,需要处理一下GridView.CellMerge事件. C# using DevExpress.XtraGrid.Views.Grid; // ... private void gridView1_CellMe

垂直时间轴HTML

1.概述 用时间点来展示事件发生点来代替用table展示一条条数据,能够给人清晰.一目了然能够看清事情发生的过程,UI页面也显示的那么清晰.如何用css+html做出时间轴展示事件点的?先来看看下面的效果 做出这样效果的时间轴展示事件点,需要了解一下知识: 1.1.css位置:position 1.2.css伪类:after,befault 1.3.css内容:content 2.CSS中Postion 语法: position : static | absolute | fixed | rel

ECharts实例开发学习笔记二——时间轴

记录一下ECharts时间轴的使用,首先是照着官方的示例做一遍,在这里不要忘了引入timelineOption.js,后面介绍如何动态创建时间轴的记录数,即根据需求可伸缩显示有多少天或者年月等轴标记数. 官网demo: [html] view plain copy <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html;chars