簡體   English   中英

從C#圖表系列中獲得y值?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM