Chart, share X axis between different series

旧时模样 提交于 2019-12-11 12:57:06

问题


I have a chart with 4 series. Each series is added at different times, depending on what is switched on/off of the app features. All series have on the x axis:

DateTime.Now.ToString("mm:ss")

so I thought that at any time the series data are available, they will be added to the chart at that time that happens on x axis. Looks like is not like that. This chart shows a blue line and a red line. The blue line started first then after few seconds I checked checkBox2 which activate the red line, that happened exactly at 27:38 (where you can see a small drop on the blue line). I do not understand why the red line starts at the far left of the chart and not at the time that was triggered (27:38).

This is my code:

        string reqTemp = textBox9.Text;
        textBox2.Text = avTemp.ToString("F");
        this.chart1.Series["Actual Temperature"].Points.AddXY(DateTime.Now.ToString("mm:ss"), avTemp);
        if (checkBox2.Checked == true)
        {
            this.chart1.Series["Requested Temperature"].Points.AddXY(DateTime.Now.ToString("mm:ss"), reqTemp);
        }   

How can I have the series added after the first one was already running starting at the time they are switched on? Basically all series sharing the same x axis.


回答1:


All series have on the x axis:

DateTime.Now.ToString("mm:ss")

I read this as: All your X-Values are added as formatted strings; this is usually a bad thing, as by doing so the X-Values have become all 0s, read: meaningless.

If you want to preserve the DateTime values you need to add the DataPoints with valid X-Values!

So you should add them as AddXY(yourDateTimeXValue, yourYValue); and set the Format as

  chart1.ChartAreas[0].AxisX.LabelStyle.Format = "mm:ss";


来源:https://stackoverflow.com/questions/17579948/chart-share-x-axis-between-different-series

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!