[DevExpress] ChartControl timeline example, controlchart

Source: Internet
Author: User

[DevExpress] ChartControl timeline example, controlchart

Key code:

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 ("profit", 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); // xydi?_ di== (xydi=) chartcontrol1.di#; // _ di=. axisY. dateTimeMeasureUnit = DateTimeMeasurementUnit. month; // _ digoal. axisY. dateTimeGridAlignment = DateTimeMeasurementUnit. month; // _ digoal. axisY. dateTimeOptions. format = DateTimeFormat. custom; // _ digoal. axisY. dateTimeOptions. formatString = "MMMM ";}}}

Bytes -------------------------------------------------------------------------------------

Using DevExpress. utils; using DevExpress. xtraCharts; namespace DevExpressChart {public static class ChartUtils {// <summary> // Add data filtering /// </summary> /// <param name = "SeriesBase"> Series </param> /// <param name = "columnName"> column name </param> /// filter value corresponding to <param name = "value"> column name </param> /// <param name = "dataFilterCondition"> DataFilterCondition enumeration </param> public static void AddDataFilter (this SeriesBase serie S, string columnName, object value, DataFilterCondition dataFilterCondition) {series. dataFilters. add (new DataFilter (columnName, value. getType (). fullName, dataFilterCondition, value ));} /// <summary> /// set the Lable angle on the X axis // </summary> /// <param name = "chart"> ChartControl </param> /// <param name = "angle"> angle </param> public static void SetXLableAngle (this ChartControl chart, int angle) {xydi1__ xyDia Gram = (xydi#) chart. di#; if (_ xydi! = Null) _ xydi.pdf. axisX. label. angle = angle ;} /// <summary> /// set the Lable angle of the Y axis // </summary> /// <param name = "chart"> ChartControl </param> /// <param name = "angle"> angle </param> public static void SetYLableAngle (this ChartControl chart, int angle) {xydi1__ xydi1_= (xydi1_) chart. di#; _ xydi. axisY. label. angle = angle ;}/// <summary> /// set ColorEach /// </summary> /// <param name = "chart "> ChartControl </param> // <param name =" colorEach "> set to ColorEach </param> public static void SetColorEach (this Series series, bool colorEach) {SeriesViewColorEachSupportBase colorEachView = (SeriesViewColorEachSupportBase) series. view; if (colorEachView! = Null) {colorEachView. colorEach = colorEach ;}} /// <summary> /// set whether to display the cross mark. /// </summary> /// <param name = "chart"> ChartControl </param> /// <param name = "crosshair"> whether to display the crosstab chart </param> public static void SetCrosshair (this ChartControl chart, bool crosshair) {chart. crosshairEnabled = crosshair? Defaboolean Boolean. true: defaboolean Boolean. false; chart. crosshairOptions. showArgumentLabels = crosshair; chart. crosshairOptions. showArgumentLine = crosshair; chart. crosshairOptions. showValueLabels = crosshair; chart. crosshairOptions. showValueLine = crosshair ;} /// <summary> /// Add the Title text of ChartControl /// </summary> /// <param name = "chart"> ChartControl </param> /// <param name = "title"> Title text </param> pub Lic static void AddTitle (this ChartControl chart, string title) {ChartTitle _ title = new ChartTitle (); _ title. text = title; chart. titles. add (_ title );} /// <summary> // set the pie Series to percent display // </summary> /// <param name = "series"> Series </param> public static void SetPiePercentage (this Series) {if (series. view is PieSeriesView) {(PiePointOptions) series. pointOptions ). percentOptions. valueAsPe Rcent = true; (PiePointOptions) series. pointOptions ). valueNumericOptions. format = NumericFormat. percent; (PiePointOptions) series. pointOptions ). valueNumericOptions. precision = 0 ;}} /// <summary> /// format the X axis into a timeline // </summary> /// <param name = "chart"> ChartControl </param> /// <param name = "dateTimeMeasureUnit"> X axis scale unit </param> /// <param name = "dateTimeGridAlignment"> unit of X axis scale spacing </param> public static voi D SetTimeAxisX (this ChartControl chart, DateTimeMeasurementUnit dateTimeMeasureUnit, DateTimeMeasurementUnit dateTimeGridAlignment) {xydi#_ di#= (xydi#) chart. di#; if (_ di! = Null) {_ digoal. axisX. dateTimeMeasureUnit = DateTimeMeasurementUnit. month; // scale unit of the X axis _ didigit. axisX. dateTimeGridAlignment = DateTimeMeasurementUnit. month; // X axis scale spacing }}/// <summary> // format the X axis into a timeline /// </summary> /// <param name = "chart"> ChartControl </param> /// <param name = "dateTimeMeasureUnit"> X axis scale unit </param> /// <param name = "dateTimeGridAlignment"> unit of X axis scale spacing </ param> // <param name = "formatString"> time Format: eg: yyyy-MM </param> public static void SetTimeAxisX (this ChartControl chart, interval dateTimeMeasureUnit, DateTimeMeasurementUnit interval, string formatString) {xydi#_ di#= (xydi#) chart. digoal; if (_ digoal! = Null) {_ digoal. axisX. dateTimeMeasureUnit = DateTimeMeasurementUnit. month; // scale unit of the X axis _ didigit. axisX. dateTimeGridAlignment = DateTimeMeasurementUnit. month; // scale spacing _ digoal on the X axis. axisX. dateTimeOptions. format = DateTimeFormat. custom; _ digoal. axisX. dateTimeOptions. formatString = formatString ;}}}}

Running effect:

Hope this is helpful! Thank you.


C #, The chartcontrol control in DevExpress draws a line chart. the X axis only displays the hour, minute, and second.

I am also using this chartcontrol control these two days.
Yes, because it is written in code.
There is nothing in the chartcontrol Control created first. For example, Diagram Legend is null.
So
First, you must create Diagram Legend and other objects and set their attributes,
Assign Diagram Legend and other objects to the corresponding properties of the chartcontrol control.
Var chart = new ChartControl (); var legend = new Legend (); var xyDiagram2D = new XYDiagram2D (); // set the attribute chart of legend xyDiagram2D. di#= xyDiagram2D; chart. legend = legend;

DevExpressXtraChartsChartControl usage

DEMOS of DevExpress is the best tutorial... and the logic in it is very rigorous, not only good help but also good programming books ··
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.