DevExpress之ChartControl实现时间轴实例
本文实例讲述了DevExpress采用ChartControl实现时间轴的方法,分享给大家供大家参考。具体实现方法如下:
关键代码如下:
usingSystem; usingSystem.Data; usingSystem.Windows.Forms; usingDevExpress.XtraCharts;
namespaceDevExpressChart { publicpartialclasswinDateTime:Form { publicwinDateTime() { InitializeComponent(); }
privatevoidwinDateTime_Load(objectsender,EventArgse) { BuilderDevChart(); } privateDataTableCreateChartData() { DataTabletable=newDataTable("Table1"); table.Columns.Add("Date",typeof(DateTime)); table.Columns.Add("Value",typeof(Int32)); table.Rows.Add(newobject[]{newDateTime(2014,5,21),10}); table.Rows.Add(newobject[]{newDateTime(2014,6,22),20}); table.Rows.Add(newobject[]{newDateTime(2014,7,23),40}); table.Rows.Add(newobject[]{newDateTime(2014,8,24),20}); table.Rows.Add(newobject[]{newDateTime(2014,9,25),30}); returntable; } privatevoidBuilderDevChart() { Series_lineSeries=newSeries("利润",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"; } } }