[英]get y value from c# chart series?
I have chart series: 我有图表系列:
Series[] tempSeries = new Series[sensorNum]; // Series to hold current/past temperature data for plotting, for each sensor
I add new points to them: 我向他们添加新的要点:
tempSeries[i].Points.AddXY(current_time, temp_F[i]); // Add new temperature data to series
Now I want to convert the series to string to send it via socket. 现在,我想将系列转换为字符串以通过套接字发送。
The question is how to get Y value from the series? 问题是如何从序列中获得Y值?
I tried this: 我尝试了这个:
private string sendAll() {
string myMsg = "";
double[,] lastTemp = new double[4, 1200];
double[,] lastWind = new double[4, 1200];
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 1200; j++){
try
{
lastTemp[i, j] = tempSeries[i].Points[j].YValues[0];
myMsg += lastTemp[i, j] + " ";
}
catch (Exception ex) {
lastTemp[i, j] = 0;
myMsg += 0 + " ";
}
}
}
myMsg += "; ";
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 1200; j++)
{
try
{
lastWind[i, j] = windSeries[i].Points[j].YValues[0];
myMsg += lastWind[i, j] + " ";
}
catch (Exception ex)
{
lastWind[i, j] = 0;
myMsg += 0 + " ";
}
}
}
MessageBox.Show(myMsg);
return myMsg;
}
But my program is freezing... 但是我的程序冻结了...
Maybe it is not the only problem with your code but you should never use string concatenation in loops ( myMsg += 0 + " ";
...) cause strings are immutable. 也许这不是代码的唯一问题,但是您永远不要在循环中使用字符串连接(
myMsg += 0 + " ";
...),因为字符串是不可变的。 Use StringBuilder
class instead. 请改用
StringBuilder
类。 Like this: 像这样:
StringBuilder sb = new StringBuilder();
for (int i = 0; i < 10000; i++)
{
sb.Append("x");
}
string x = sb.ToString();
Here is detailed info on why strings are immutable and what are the consequences of it: http://en.morzel.net/post/2010/01/26/Why-strings-are-immutable-and-what-are-implications-of-it.aspx 以下是有关为什么字符串不可变及其后果的详细信息: http : //en.morzel.net/post/2010/01/26/Why-strings-are-immutable-and-what-are-implications它的.aspx
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.