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