[英]get y value from c# chart series?
我有图表系列:
Series[] tempSeries = new Series[sensorNum]; // Series to hold current/past temperature data for plotting, for each sensor
我向他们添加新的要点:
tempSeries[i].Points.AddXY(current_time, temp_F[i]); // Add new temperature data to series
现在,我想将系列转换为字符串以通过套接字发送。
问题是如何从序列中获得Y值?
我尝试了这个:
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;
}
但是我的程序冻结了...
也许这不是代码的唯一问题,但是您永远不要在循环中使用字符串连接( myMsg += 0 + " ";
...),因为字符串是不可变的。 请改用StringBuilder
类。 像这样:
StringBuilder sb = new StringBuilder();
for (int i = 0; i < 10000; i++)
{
sb.Append("x");
}
string x = sb.ToString();
以下是有关为什么字符串不可变及其后果的详细信息: 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.