问题描述
我有一个4系列的图表。每个系列在不同的时间添加,取决于打开/关闭的应用程序功能。所有系列都在x轴上:
DateTime.Now.ToString(mm:ss)
所以我认为在任何时候系列数据都可用,它们将被添加到当时发生在x上的图表轴。看起来不像那样。此图表显示蓝色线和红色线。蓝线开始,然后几秒钟后,我检查了checkBox2激活红线,这恰好发生在27:38(在那里你可以看到一个小滴蓝线上)。我不明白为什么红线起始于图表的最左边,而不是在被触发的时候(27:38)。
这是我的代码:
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);
}
如何在第一个已经开始运行之后添加系列上?基本上所有系列共享同一个x轴。
解决方案我读为:所有的X值都添加为格式化的字符串;这通常是一件坏事,因为这样做 X值已变为 0s
,读为:无意义。
如果要保留 DateTime
值,您需要添加 DataPoints
因此您应该将它们添加为 AddXY(yourDateTimeXValue,yourYValue);
并设置 code>格式
为
chart1.ChartAreas [0] .AxisX.LabelStyle.Format =mm:ss;
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.
解决方案 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";
这篇关于图表,共享X轴在不同系列之间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!