1
votes

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);
        }   

enter image description here

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

1 Answers

0
votes

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";