从c#图表系列中获取y值
本文关键字:获取 系列 | 更新日期: 2023-09-27 18:15:52
我有图表系列:
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-of-it.aspx