Hi~
以下是我的功能代碼
資料來源是由別支軟體吐出的一連串數值
然後透過MonitorLanDataControl()來取得資料並且經過整理處理後送到addLanData()來繪製
繪製出問題有一定的規律性
繪製47次之後就會出現亂畫的狀況
再麻煩您協助了
感謝
-
- private void MonitorLanDataControl()
- {
- addLanListFunction();
- Double totalLenUPValue = 0;
- Double totalLenDownValue = 0;
- if (totalLenReceiveList.Count > 0)
- {
- for (int i = 0; i < totalLenReceiveList.Count; i++)
- {
- Double testvalue = (Convert.ToDouble((totalLenReceiveList[i])[1]) / 1024) * 8;
- totalLenDownValue += testvalue;
- if (File.Exists("database\\tmp\" + (totalLenReceiveList[i])[0] + ".log") == true)
- {
- try
- {
- StreamReader sr = new StreamReader("database\\tmp\" + (totalLenReceiveList[i])[0] + ".log");
- string[] tmpdata = sr.ReadToEnd().Split('\n');
- sr.Close();
- List<string> tmppoint = new List<string>();
- for (int j = 0; j < tmpdata.Length; j++)
- {
- if (tmpdata[j] != "")
- {
- tmppoint.Add(Regex.Replace(tmpdata[j], "\\r", String.Empty));
- }
- }
- StreamWriter sw = new StreamWriter("database\\tmp\" + (totalLenReceiveList[i])[0] + ".log", false);
- if (tmppoint.Count < 15)
- {
- try
- {
- for (int j = 0; j < tmppoint.Count; j++)
- {
- sw.WriteLine(tmppoint[j]);
- }
- }
- catch (Exception ex)
- {
- }
- }
- else
- {
- try
- {
- for (int j = tmppoint.Count - 15; j < tmppoint.Count; j++)
- {
- sw.WriteLine(tmppoint[j]);
- }
- }
- catch (Exception ex)
- {
- }
- }
- sw.Close();
- }
- catch (Exception ex)
- {
- }
- }
- try
- {
- StreamWriter sw = new StreamWriter("database\\tmp\" + (totalLenReceiveList[i])[0] + ".log", true);
- double tmpLenReceive = (Convert.ToDouble((totalLenReceiveList[i])[1]) / 1024) * 8;
- sw.WriteLine((totalLenReceiveList[i])[0] + ";" + tmpLenReceive);
- sw.Close();
- }
- catch (Exception ex)
- {
- }
- }
- }
- for (int i = 0; i < totalLenSendList.Count; i++)
- {
- Double testvalue = (Convert.ToDouble((totalLenSendList[i])[1]) / 1024) * 8;
- totalLenUPValue += testvalue;
- if (File.Exists("database\\tmp\" + (totalLenSendList[i])[0] + ".log") == true)
- {
- try
- {
- StreamReader sr = new StreamReader("database\\tmp\\up_" + (totalLenSendList[i])[0] + ".log");
- string[] tmpdata = sr.ReadToEnd().Split('\n');
- sr.Close();
- List<string> tmppoint = new List<string>();
- for (int j = 0; j < tmpdata.Length; j++)
- {
- if (tmpdata[j] != "")
- {
- tmppoint.Add(Regex.Replace(tmpdata[j], "\\r", String.Empty));
- }
- }
- StreamWriter sw = new StreamWriter("database\\tmp\\up_" + (totalLenSendList[i])[0] + ".log", false);
- if (tmppoint.Count < 15)
- {
- try
- {
- for (int j = 0; j < tmppoint.Count; j++)
- {
- sw.WriteLine(tmppoint[j]);
- }
- }
- catch (Exception ex)
- {
- }
- }
- else
- {
- try
- {
- for (int j = tmppoint.Count - 15; j < tmppoint.Count; j++)
- {
- sw.WriteLine(tmppoint[j]);
- }
- }
- catch (Exception ex)
- {
- }
- }
- sw.Close();
- }
- catch (Exception ex)
- {
- }
- }
- try
- {
- StreamWriter sw = new StreamWriter("database\\tmp\\up_" + (totalLenSendList[i])[0] + ".log", true);
- double tmpupLenReceive = (Convert.ToDouble((totalLenSendList[i])[1]) / 1024) * 8;
- sw.WriteLine((totalLenSendList[i])[0] + ";" + tmpupLenReceive);
- sw.Close();
- }
- catch (Exception ex)
- {
- }
- }
- if (File.Exists("database\\tmp\\totaldown.log") == true)
- {
- try
- {
- StreamReader sr = new StreamReader("database\\tmp\\totaldown.log");
- string[] tmpdata = sr.ReadToEnd().Split('\n');
- sr.Close();
- List<string> tmppoint = new List<string>();
- for (int j = 0; j < tmpdata.Length; j++)
- {
- if (tmpdata[j] != "")
- {
- tmppoint.Add(Regex.Replace(tmpdata[j], "\\r", String.Empty));
- }
- }
- StreamWriter sw = new StreamWriter("database\\tmp\\totaldown.log", false);
- if (tmppoint.Count < 15)
- {
- try
- {
- for (int j = 0; j < tmppoint.Count; j++)
- {
- sw.WriteLine(tmppoint[j]);
- }
- }
- catch (Exception ex)
- {
- }
- }
- else
- {
- try
- {
- for (int j = tmppoint.Count - 15; j < tmppoint.Count; j++)
- {
- sw.WriteLine(tmppoint[j]);
- }
- }
- catch (Exception ex)
- {
- }
- }
- sw.Close();
- }
- catch (Exception ex)
- {
- }
- }
- try
- {
- StreamWriter sw = new StreamWriter("database\\tmp\\totaldown.log", true);
- sw.WriteLine("total;" + totalLenDownValue.ToString());
- sw.Close();
- }
- catch
- {
- }
- if (File.Exists("database\\tmp\\totalup.log") == true)
- {
- try
- {
- StreamReader sr = new StreamReader("database\\tmp\\totalup.log");
- string[] tmpdata = sr.ReadToEnd().Split('\n');
- sr.Close();
- List<string> tmppoint = new List<string>();
- for (int j = 0; j < tmpdata.Length; j++)
- {
- if (tmpdata[j] != "")
- {
- tmppoint.Add(Regex.Replace(tmpdata[j], "\\r", String.Empty));
- }
- }
- StreamWriter sw = new StreamWriter("database\\tmp\\totalup.log", false);
- if (tmppoint.Count < 15)
- {
- try
- {
- for (int j = 0; j < tmppoint.Count; j++)
- {
- sw.WriteLine(tmppoint[j]);
- }
- }
- catch (Exception ex)
- {
- }
- }
- else
- {
- try
- {
- for (int j = tmppoint.Count - 15; j < tmppoint.Count; j++)
- {
- sw.WriteLine(tmppoint[j]);
- }
- }
- catch (Exception ex)
- {
- }
- }
- sw.Close();
- }
- catch (Exception ex)
- {
- }
- }
- try
- {
- StreamWriter sw = new StreamWriter("database\\tmp\\totalup.log", true);
- sw.WriteLine("total;" + totalLenUPValue.ToString());
- sw.Close();
- }
- catch
- {
- }
- List<List<double>> landataList = new List<List<double>>();
- List<List<double>> timePoint = new List<List<double>>();
- List<string> LineColorList = new List<string>();
- List<string> titleList = new List<string>();
- if (monitor_lanusage == "download")
- {
- lanchartY.Content = FindResource("monitor_x_download_title");
- for (int i = 0; i < LanmonitorChartList.Count; i++)
- {
- if ((LanmonitorChartList[i])[1].ToString() == "1")
- {
- string pname = ((LanmonitorChartList[i])[0].ToString().Split('.'))[0];
- string[] RecData = new string[15];
- try
- {
- if (pname != "Total")
- {
- StreamReader sr = new StreamReader("database\\tmp\" + pname + ".log");
- string[] tmpRecData = sr.ReadToEnd().Split('\n');
- for (int j = 0; j < 15; j++)
- {
- RecData[j] = Regex.Replace(tmpRecData[tmpRecData.Length - (j + 2)], "\\r", String.Empty);
- }
- sr.Close();
- }
- else
- {
- StreamReader sr = new StreamReader("database\\tmp\\totaldown.log");
- string[] tmpRecData = sr.ReadToEnd().Split('\n');
- for (int j = 0; j < 15; j++)
- {
- RecData[j] = Regex.Replace(tmpRecData[tmpRecData.Length - (j + 2)], "\\r", String.Empty);
- }
- sr.Close();
- }
- }
- catch (Exception ex)
- {
- }
- List<double> tmpValueList = new List<double>();
- List<double> tmptimeList = new List<double>();
- for (int j = RecData.Length; j > 1; j--)
- {
- double value = 0;
- if (RecData[j - 1] != null)
- value = (Convert.ToDouble((RecData[j - 1].Split(';'))[1]) / 1024) * 8;
- double time = DateTime.Now.AddSeconds((j * -1)).Second;
- tmpValueList.Add(value);
- tmptimeList.Add(time);
- }
- landataList.Add(tmpValueList);
- timePoint.Add(tmptimeList);
- LineColorList.Add((LanmonitorChartList[i])[2].ToString());
- titleList.Add((LanmonitorChartList[i])[0].ToString());
- }
- }
- }
- else
- {
- lanchartY.Content = FindResource("monitor_x_upload_title").ToString();
- for (int i = 0; i < LanmonitorChartList.Count; i++)
- {
- if ((LanmonitorChartList[i])[1].ToString() == "1")
- {
- string pname = ((LanmonitorChartList[i])[0].ToString().Split('.'))[0];
- string[] RecData = new string[15];
- try
- {
- if (pname != "Total")
- {
- StreamReader sr = new StreamReader("database\\tmp\\up_" + pname + ".log");
- string[] tmpRecData = sr.ReadToEnd().Split('\n');
- for (int j = 0; j < 15; j++)
- {
- RecData[j] = Regex.Replace(tmpRecData[tmpRecData.Length - (j + 2)], "\\r", String.Empty);
- }
- sr.Close();
- }
- else
- {
- StreamReader sr = new StreamReader("database\\tmp\\totalup.log");
- string[] tmpRecData = sr.ReadToEnd().Split('\n');
- for (int j = 0; j < 15; j++)
- {
- RecData[j] = Regex.Replace(tmpRecData[tmpRecData.Length - (j + 2)], "\\r", String.Empty);
- }
- sr.Close();
- }
- }
- catch (Exception ex)
- {
- }
- List<double> tmpValueList = new List<double>();
- List<double> tmptimeList = new List<double>();
- for (int j = RecData.Length; j > 1; j--)
- {
- double value = 0;
- if (RecData[j - 1] != null)
- value = (Convert.ToDouble((RecData[j - 1].Split(';'))[1]) / 1024) * 8;
- double time = DateTime.Now.AddSeconds((j * -1)).Second;
- tmpValueList.Add(value);
- tmptimeList.Add(time);
- }
- landataList.Add(tmpValueList);
- timePoint.Add(tmptimeList);
- LineColorList.Add((LanmonitorChartList[i])[2].ToString());
- titleList.Add((LanmonitorChartList[i])[0].ToString());
- }
- }
- }
- addLanData(landataList, timePoint, LineColorList, titleList);
- }
- private void addLanData(List<List<double>> valuelist, List<List<double>> time, List<string> lineColor, List<string> title)
- {
- lanusage_chart.Data.Children.Clear();
- if (valuelist.Count == time.Count)
- {
- for (int j = 0; j < valuelist.Count; j++)
- {
- XYDataSeries showdata = new XYDataSeries();
- showdata.ConnectionStroke = new SolidColorBrush((Color)ColorConverter.ConvertFromString(lineColor[j]));
- showdata.XValuesSource = time[j];
- showdata.ValuesSource = valuelist[j];
- lanusage_chart.Data.Children.Add(showdata);
- }
- }
- }
复制代码 |