How to set the X axis of the mschart to time

Source: Internet
Author: User

Recently, I used C # To develop charts, compared directorchart, dontnetcharting, and teechart, and finally chose Microsoft mschart for development. I have been exploring the X axis as the timeline for a long time and finally achieved the desired results.

Interface effect:



Core code:
 

Source code

Using system; using system. collections. generic; using system. componentmodel; using system. data; using system. drawing; using system. text; using system. windows. forms; using componentfactory. kryton. toolkit; using system. windows. forms. datavisualization. charting; namespace krypton1_test {public partial class form4: componentfactory. kryton. toolkit. kryptonform {public form4 () {initializecomponent ();} private void form4_load (Object sender, eventargs e) {// clear the original data cache chart1.series [0]. points. clear (); // define the chart size and size chart1.width = width-100; chart1.height = height-100; // define the X axis and Y axis data double [] ydata = {20, 3, 23, 6}; datetime [] xdate = new datetime [] {datetime. parse ("09:10:02"), datetime. parse ("09:10:10"), datetime. parse ("09:10:15"), datetime. parse ("09:10:20")}; // follow the steps below to draw chartarea first, and then draw a series drawing // chartarea background color chart1.backcolor = color. azure; // set chart1.chartareas [0] on the X axis. axisx. title = "time"; chart1.chartareas [0]. axisx. titlealignment = stringalignment. near; chart1.chartareas [0]. axisx. majorgrid. enabled = false; // do not display the vertical split line /******************************** **************************************** // * This article focuses on setting the time format * if you want to display the first time coordinate of the origin, minimum Time, interval type, three parameters, such as the time interval value, are *//****************************** **************************************** **/chart1.chartareas [0]. axisx. labelstyle. format = "HH: mm: SS"; // time format displayed on the X axis. If hh is in uppercase, it is in 24-hour format, and if hh is in lowercase, it is in chart1.chartareas [0]. axisx. minimum = datetime. parse ("09:10:02 "). tooadate (); chart1.chartareas [0]. axisx. maximum = datetime. parse ("09:10:21 "). tooadate (); chart1.chartareas [0]. axisx. intervaltype = datetimeintervaltype. seconds; // For time data, the interval can be second, minute, or hour chart1.chartareas [0]. axisx. interval = datetime. parse ("00:00:02 "). second; // The interval is 1 second. // set chart1.chartareas [0] For the Y axis. axisy. title = "data point"; chart1.chartareas [0]. axisy. titlealignment = stringalignment. center; chart1.chartareas [0]. axisy. majorgrid. enabled = true; // display the horizontal split line chart1.chartareas [0]. axisy. minimum = 0; chart1.chartareas [0]. axisy. maximum = 25; chart1.chartareas [0]. axisy. interval = 5; // series draw chart1.series [0]. legendtext = "temperature point"; chart1.series [0]. charttype = seriescharttype. spline; chart1.series [0]. xvaluetype = chartvaluetype. datetime; chart1.series [0]. isvalueshownaslabel = true; // display the data point value chart1.series [0]. markerstyle = markerstyle. circle; // Add the data point to the series chart for (INT I = 0; I <xdate. length; I ++) {chart1.series [0]. points. addxy (xdate [I], ydata [I]) ;}}}

  

How to set the X axis of the mschart to time

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.