找回密码
 立即注册

QQ登录

只需一步,快速开始

dec691028

注册会员

2

主题

9

帖子

23

积分

注册会员

积分
23
最新发帖
dec691028
注册会员   /  发表于:2015-12-17 23:25  /   查看:9664  /  回复:15
Hi~您好

我寫了一份Line Chart動態圖表,圖表有機率出現以下畫面



我需要的是多個項目同時動態繪製,Dynamic Sample只有繪製一條線
因此我的寫法如下

        private void addLanData(List<List<double>> valuelist, List<List<double>> time, List<string> lineColor, List<string> title)
        {
            lanusage_chart.BeginUpdate();
            lanusage_chart.Data.Children.Clear();
            List<List<int>> tmpdata = new List<List<int>>();

            for (int i = 0; i < valuelist.Count; i++)
            {
                XYDataSeries showdata = new XYDataSeries();
                showdata.ConnectionStroke = new SolidColorBrush((Color)ColorConverter.ConvertFromString(lineColor));
                showdata.XValuesSource = time;
                showdata.ValuesSource = valuelist;

                lanusage_chart.Data.Children.Add(showdata);
            }

            lanusage_chart.EndUpdate();
        }



請問該如何解決此問題

感謝

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x

15 个回复

正序浏览
gw0506
超级版主   /  发表于:2015-12-28 16:20:00
16#
有其他问题欢迎继续发帖讨论。本帖关闭。
回复 使用道具 举报
dec691028
注册会员   /  发表于:2015-12-25 19:12:00
15#
Hi~ Alice

感謝您的協助
我已經解決問題了
控件已經可以正常的繪製線段

非常感謝您
回复 使用道具 举报
Alice
社区贡献组   /  发表于:2015-12-25 17:55:00
14#
回复 13楼dec691028的帖子

谢谢您提供的代码。
我们对您的代码进行测试,但是还是无法运行调试。
其中addLanListFunction()方法没有,我注销掉了。但是totalLenReceiveList/totalLenSendList/LanmonitorChartList都是未知的数据,影响到了数据的调试。
请点击评分,对我的服务做出评价!  5分为非常满意!

葡萄城控件服务团队

官方网站: http://www.gcpowertools.com.cn
回复 使用道具 举报
dec691028
注册会员   /  发表于:2015-12-25 13:40:00
13#
Hi~
以下是我的功能代碼
資料來源是由別支軟體吐出的一連串數值
然後透過MonitorLanDataControl()來取得資料並且經過整理處理後送到addLanData()來繪製

繪製出問題有一定的規律性
繪製47次之後就會出現亂畫的狀況

再麻煩您協助了

感謝

  1.       
  2. private void MonitorLanDataControl()
  3.         {
  4.             addLanListFunction();

  5.             Double totalLenUPValue = 0;
  6.             Double totalLenDownValue = 0;

  7.             if (totalLenReceiveList.Count > 0)
  8.             {
  9.                 for (int i = 0; i < totalLenReceiveList.Count; i++)
  10.                 {
  11.                     Double testvalue = (Convert.ToDouble((totalLenReceiveList[i])[1]) / 1024) * 8;
  12.                     totalLenDownValue += testvalue;

  13.                     if (File.Exists("database\\tmp\" + (totalLenReceiveList[i])[0] + ".log") == true)
  14.                     {
  15.                         try
  16.                         {
  17.                             StreamReader sr = new StreamReader("database\\tmp\" + (totalLenReceiveList[i])[0] + ".log");
  18.                             string[] tmpdata = sr.ReadToEnd().Split('\n');
  19.                             sr.Close();

  20.                             List<string> tmppoint = new List<string>();
  21.                             for (int j = 0; j < tmpdata.Length; j++)
  22.                             {
  23.                                 if (tmpdata[j] != "")
  24.                                 {
  25.                                     tmppoint.Add(Regex.Replace(tmpdata[j], "\\r", String.Empty));
  26.                                 }
  27.                             }

  28.                             StreamWriter sw = new StreamWriter("database\\tmp\" + (totalLenReceiveList[i])[0] + ".log", false);
  29.                             if (tmppoint.Count < 15)
  30.                             {
  31.                                 try
  32.                                 {
  33.                                     for (int j = 0; j < tmppoint.Count; j++)
  34.                                     {
  35.                                         sw.WriteLine(tmppoint[j]);
  36.                                     }
  37.                                 }
  38.                                 catch (Exception ex)
  39.                                 {
  40.                                 }
  41.                             }
  42.                             else
  43.                             {
  44.                                 try
  45.                                 {
  46.                                     for (int j = tmppoint.Count - 15; j < tmppoint.Count; j++)
  47.                                     {
  48.                                         sw.WriteLine(tmppoint[j]);
  49.                                     }
  50.                                 }
  51.                                 catch (Exception ex)
  52.                                 {
  53.                                 }
  54.                             }

  55.                             sw.Close();
  56.                         }
  57.                         catch (Exception ex)
  58.                         {
  59.                         }
  60.                     }

  61.                     try
  62.                     {
  63.                         StreamWriter sw = new StreamWriter("database\\tmp\" + (totalLenReceiveList[i])[0] + ".log", true);
  64.                         double tmpLenReceive = (Convert.ToDouble((totalLenReceiveList[i])[1]) / 1024) * 8;
  65.                         sw.WriteLine((totalLenReceiveList[i])[0] + ";" + tmpLenReceive);
  66.                         sw.Close();
  67.                     }
  68.                     catch (Exception ex)
  69.                     {
  70.                     }
  71.                 }
  72.             }

  73.             for (int i = 0; i < totalLenSendList.Count; i++)
  74.             {
  75.                 Double testvalue = (Convert.ToDouble((totalLenSendList[i])[1]) / 1024) * 8;
  76.                 totalLenUPValue += testvalue;

  77.                 if (File.Exists("database\\tmp\" + (totalLenSendList[i])[0] + ".log") == true)
  78.                 {
  79.                     try
  80.                     {
  81.                         StreamReader sr = new StreamReader("database\\tmp\\up_" + (totalLenSendList[i])[0] + ".log");
  82.                         string[] tmpdata = sr.ReadToEnd().Split('\n');
  83.                         sr.Close();

  84.                         List<string> tmppoint = new List<string>();
  85.                         for (int j = 0; j < tmpdata.Length; j++)
  86.                         {
  87.                             if (tmpdata[j] != "")
  88.                             {
  89.                                 tmppoint.Add(Regex.Replace(tmpdata[j], "\\r", String.Empty));
  90.                             }
  91.                         }

  92.                         StreamWriter sw = new StreamWriter("database\\tmp\\up_" + (totalLenSendList[i])[0] + ".log", false);
  93.                         if (tmppoint.Count < 15)
  94.                         {
  95.                             try
  96.                             {
  97.                                 for (int j = 0; j < tmppoint.Count; j++)
  98.                                 {
  99.                                     sw.WriteLine(tmppoint[j]);
  100.                                 }
  101.                             }
  102.                             catch (Exception ex)
  103.                             {
  104.                             }
  105.                         }
  106.                         else
  107.                         {
  108.                             try
  109.                             {
  110.                                 for (int j = tmppoint.Count - 15; j < tmppoint.Count; j++)
  111.                                 {
  112.                                     sw.WriteLine(tmppoint[j]);
  113.                                 }
  114.                             }
  115.                             catch (Exception ex)
  116.                             {
  117.                             }
  118.                         }

  119.                         sw.Close();
  120.                     }
  121.                     catch (Exception ex)
  122.                     {
  123.                     }
  124.                 }

  125.                 try
  126.                 {
  127.                     StreamWriter sw = new StreamWriter("database\\tmp\\up_" + (totalLenSendList[i])[0] + ".log", true);
  128.                     double tmpupLenReceive = (Convert.ToDouble((totalLenSendList[i])[1]) / 1024) * 8;
  129.                     sw.WriteLine((totalLenSendList[i])[0] + ";" + tmpupLenReceive);
  130.                     sw.Close();
  131.                 }
  132.                 catch (Exception ex)
  133.                 {
  134.                 }
  135.             }

  136.             if (File.Exists("database\\tmp\\totaldown.log") == true)
  137.             {
  138.                 try
  139.                 {
  140.                     StreamReader sr = new StreamReader("database\\tmp\\totaldown.log");
  141.                     string[] tmpdata = sr.ReadToEnd().Split('\n');
  142.                     sr.Close();

  143.                     List<string> tmppoint = new List<string>();
  144.                     for (int j = 0; j < tmpdata.Length; j++)
  145.                     {
  146.                         if (tmpdata[j] != "")
  147.                         {
  148.                             tmppoint.Add(Regex.Replace(tmpdata[j], "\\r", String.Empty));
  149.                         }
  150.                     }

  151.                     StreamWriter sw = new StreamWriter("database\\tmp\\totaldown.log", false);
  152.                     if (tmppoint.Count < 15)
  153.                     {
  154.                         try
  155.                         {
  156.                             for (int j = 0; j < tmppoint.Count; j++)
  157.                             {
  158.                                 sw.WriteLine(tmppoint[j]);
  159.                             }
  160.                         }
  161.                         catch (Exception ex)
  162.                         {
  163.                         }
  164.                     }
  165.                     else
  166.                     {
  167.                         try
  168.                         {
  169.                             for (int j = tmppoint.Count - 15; j < tmppoint.Count; j++)
  170.                             {
  171.                                 sw.WriteLine(tmppoint[j]);
  172.                             }
  173.                         }
  174.                         catch (Exception ex)
  175.                         {
  176.                         }
  177.                     }

  178.                     sw.Close();
  179.                 }
  180.                 catch (Exception ex)
  181.                 {
  182.                 }
  183.             }

  184.             try
  185.             {
  186.                 StreamWriter sw = new StreamWriter("database\\tmp\\totaldown.log", true);
  187.                 sw.WriteLine("total;" + totalLenDownValue.ToString());
  188.                 sw.Close();
  189.             }
  190.             catch
  191.             {
  192.             }

  193.             if (File.Exists("database\\tmp\\totalup.log") == true)
  194.             {
  195.                 try
  196.                 {
  197.                     StreamReader sr = new StreamReader("database\\tmp\\totalup.log");
  198.                     string[] tmpdata = sr.ReadToEnd().Split('\n');
  199.                     sr.Close();

  200.                     List<string> tmppoint = new List<string>();
  201.                     for (int j = 0; j < tmpdata.Length; j++)
  202.                     {
  203.                         if (tmpdata[j] != "")
  204.                         {
  205.                             tmppoint.Add(Regex.Replace(tmpdata[j], "\\r", String.Empty));
  206.                         }
  207.                     }

  208.                     StreamWriter sw = new StreamWriter("database\\tmp\\totalup.log", false);
  209.                     if (tmppoint.Count < 15)
  210.                     {
  211.                         try
  212.                         {
  213.                             for (int j = 0; j < tmppoint.Count; j++)
  214.                             {
  215.                                 sw.WriteLine(tmppoint[j]);
  216.                             }
  217.                         }
  218.                         catch (Exception ex)
  219.                         {
  220.                         }
  221.                     }
  222.                     else
  223.                     {
  224.                         try
  225.                         {
  226.                             for (int j = tmppoint.Count - 15; j < tmppoint.Count; j++)
  227.                             {
  228.                                 sw.WriteLine(tmppoint[j]);
  229.                             }
  230.                         }
  231.                         catch (Exception ex)
  232.                         {
  233.                         }
  234.                     }

  235.                     sw.Close();
  236.                 }
  237.                 catch (Exception ex)
  238.                 {
  239.                 }
  240.             }

  241.             try
  242.             {
  243.                 StreamWriter sw = new StreamWriter("database\\tmp\\totalup.log", true);
  244.                 sw.WriteLine("total;" + totalLenUPValue.ToString());
  245.                 sw.Close();
  246.             }
  247.             catch
  248.             {
  249.             }


  250.             List<List<double>> landataList = new List<List<double>>();
  251.             List<List<double>> timePoint = new List<List<double>>();
  252.             List<string> LineColorList = new List<string>();
  253.             List<string> titleList = new List<string>();

  254.             if (monitor_lanusage == "download")
  255.             {
  256.                 lanchartY.Content = FindResource("monitor_x_download_title");
  257.                 for (int i = 0; i < LanmonitorChartList.Count; i++)
  258.                 {
  259.                     if ((LanmonitorChartList[i])[1].ToString() == "1")
  260.                     {
  261.                         string pname = ((LanmonitorChartList[i])[0].ToString().Split('.'))[0];
  262.                         string[] RecData = new string[15];

  263.                         try
  264.                         {
  265.                             if (pname != "Total")
  266.                             {
  267.                                 StreamReader sr = new StreamReader("database\\tmp\" + pname + ".log");
  268.                                 string[] tmpRecData = sr.ReadToEnd().Split('\n');
  269.                                 for (int j = 0; j < 15; j++)
  270.                                 {
  271.                                     RecData[j] = Regex.Replace(tmpRecData[tmpRecData.Length - (j + 2)], "\\r", String.Empty);
  272.                                 }

  273.                                 sr.Close();
  274.                             }
  275.                             else
  276.                             {
  277.                                 StreamReader sr = new StreamReader("database\\tmp\\totaldown.log");
  278.                                 string[] tmpRecData = sr.ReadToEnd().Split('\n');
  279.                                 for (int j = 0; j < 15; j++)
  280.                                 {
  281.                                     RecData[j] = Regex.Replace(tmpRecData[tmpRecData.Length - (j + 2)], "\\r", String.Empty);
  282.                                 }

  283.                                 sr.Close();
  284.                             }
  285.                         }
  286.                         catch (Exception ex)
  287.                         {
  288.                         }

  289.                         List<double> tmpValueList = new List<double>();
  290.                         List<double> tmptimeList = new List<double>();
  291.                         for (int j = RecData.Length; j > 1; j--)
  292.                         {
  293.                             double value = 0;
  294.                             if (RecData[j - 1] != null)
  295.                                 value = (Convert.ToDouble((RecData[j - 1].Split(';'))[1]) / 1024) * 8;


  296.                             double time = DateTime.Now.AddSeconds((j * -1)).Second;
  297.                             tmpValueList.Add(value);
  298.                             tmptimeList.Add(time);
  299.                         }

  300.                         landataList.Add(tmpValueList);
  301.                         timePoint.Add(tmptimeList);
  302.                         LineColorList.Add((LanmonitorChartList[i])[2].ToString());
  303.                         titleList.Add((LanmonitorChartList[i])[0].ToString());
  304.                     }
  305.                 }
  306.             }
  307.             else
  308.             {
  309.                 lanchartY.Content = FindResource("monitor_x_upload_title").ToString();
  310.                 for (int i = 0; i < LanmonitorChartList.Count; i++)
  311.                 {
  312.                     if ((LanmonitorChartList[i])[1].ToString() == "1")
  313.                     {
  314.                         string pname = ((LanmonitorChartList[i])[0].ToString().Split('.'))[0];
  315.                         string[] RecData = new string[15];

  316.                         try
  317.                         {
  318.                             if (pname != "Total")
  319.                             {
  320.                                 StreamReader sr = new StreamReader("database\\tmp\\up_" + pname + ".log");
  321.                                 string[] tmpRecData = sr.ReadToEnd().Split('\n');
  322.                                 for (int j = 0; j < 15; j++)
  323.                                 {
  324.                                     RecData[j] = Regex.Replace(tmpRecData[tmpRecData.Length - (j + 2)], "\\r", String.Empty);
  325.                                 }

  326.                                 sr.Close();
  327.                             }
  328.                             else
  329.                             {
  330.                                 StreamReader sr = new StreamReader("database\\tmp\\totalup.log");
  331.                                 string[] tmpRecData = sr.ReadToEnd().Split('\n');
  332.                                 for (int j = 0; j < 15; j++)
  333.                                 {
  334.                                     RecData[j] = Regex.Replace(tmpRecData[tmpRecData.Length - (j + 2)], "\\r", String.Empty);
  335.                                 }

  336.                                 sr.Close();
  337.                             }
  338.                         }
  339.                         catch (Exception ex)
  340.                         {
  341.                         }

  342.                         List<double> tmpValueList = new List<double>();
  343.                         List<double> tmptimeList = new List<double>();
  344.                         for (int j = RecData.Length; j > 1; j--)
  345.                         {
  346.                             double value = 0;
  347.                             if (RecData[j - 1] != null)
  348.                                 value = (Convert.ToDouble((RecData[j - 1].Split(';'))[1]) / 1024) * 8;


  349.                             double time = DateTime.Now.AddSeconds((j * -1)).Second;
  350.                             tmpValueList.Add(value);
  351.                             tmptimeList.Add(time);
  352.                         }

  353.                         landataList.Add(tmpValueList);
  354.                         timePoint.Add(tmptimeList);
  355.                         LineColorList.Add((LanmonitorChartList[i])[2].ToString());
  356.                         titleList.Add((LanmonitorChartList[i])[0].ToString());
  357.                     }
  358.                 }
  359.             }

  360.             addLanData(landataList, timePoint, LineColorList, titleList);
  361.         }

  362.         private void addLanData(List<List<double>> valuelist, List<List<double>> time, List<string> lineColor, List<string> title)
  363.         {
  364.             lanusage_chart.Data.Children.Clear();
  365.             if (valuelist.Count == time.Count)
  366.             {
  367.                 for (int j = 0; j < valuelist.Count; j++)
  368.                 {

  369.                     XYDataSeries showdata = new XYDataSeries();
  370.                     showdata.ConnectionStroke = new SolidColorBrush((Color)ColorConverter.ConvertFromString(lineColor[j]));
  371.                     showdata.XValuesSource = time[j];
  372.                     showdata.ValuesSource = valuelist[j];

  373.                     lanusage_chart.Data.Children.Add(showdata);
  374.                 }
  375.             }
  376.         }
复制代码
回复 使用道具 举报
Alice
社区贡献组   /  发表于:2015-12-25 10:32:00
12#
回复 11楼dec691028的帖子

很抱歉您的代码我的确无法调试,这段代码并没有提供addLanData是如何被调用的,也没有提供参数valueList, time, lineColor和title。
因此对于您的代码无法推测哪里出错。

有关您提到的问题,6楼已经提供了示例和源代码。
我们也有博客演示多个序列的绑定:http://blog.gcpowertools.com.cn/ ... iesItemsSource.aspx
您可以根据示例来完成您的需求。

如果想让我们帮助分析错误原因,还请您提供可以重现或是调试问题的Demo,谢谢。
请点击评分,对我的服务做出评价!  5分为非常满意!

葡萄城控件服务团队

官方网站: http://www.gcpowertools.com.cn
回复 使用道具 举报
dec691028
注册会员   /  发表于:2015-12-25 02:06:00
11#
您好,以下是我的代碼

valuelist <-- Y軸雙重陣列變數
time <-- X軸雙重陣列變數
lineColor <-- 線段色彩

lanusage_chart <-- Chart本體      

private void addLanData(List<List<double>> valuelist, List<List<double>> time, List<string> lineColor, List<string> title)
        {
            lanusage_chart.BeginUpdate();
            lanusage_chart.Data.Children.Clear();
            List<List<int>> tmpdata = new List<List<int>>();

            for (int i = 0; i < valuelist.Count; i++)
            {
                XYDataSeries showdata = new XYDataSeries();
                showdata.ConnectionStroke = new SolidColorBrush((Color)ColorConverter.ConvertFromString(lineColor));
                showdata.XValuesSource = time;
                showdata.ValuesSource = valuelist;

                lanusage_chart.Data.Children.Add(showdata);
            }
            //檢查有幾組線段的資料,並且繪製到XYDataSeries內容中

            lanusage_chart.EndUpdate();
        }

如果這樣的Code沒有幫助的話,是否可以請您給我一個Sample Code
我要求的功能如下

1. 可一次畫多條線段
2. 線段可以指定顏色
3. 線段的顏色可以動態的調整
4. 圖表中一次只可畫出15個Point

非常感謝您的協助
回复 使用道具 举报
Alice
社区贡献组   /  发表于:2015-12-23 16:54:00
10#
回复 9楼dec691028的帖子

谢谢您的反馈。
如果您的程序出现问题,需要我们协助,建议您提供可以重现您提到问题的Demo,我们可以协助您进行测试,才能找到问题的原因。
请点击评分,对我的服务做出评价!  5分为非常满意!

葡萄城控件服务团队

官方网站: http://www.gcpowertools.com.cn
回复 使用道具 举报
dec691028
注册会员   /  发表于:2015-12-23 14:56:00
9#
Hi~ 感謝您的協助

但我想了解的是我先前的寫法問題出在哪?
這樣子寫一開始是可以正常繪圖的
一秒繪製一個新點

可是持續跑一小段時間後變會出錯15秒,有就是圖表上的X軸的數量
當15秒後又會正常繪圖

感謝
回复 使用道具 举报
Alice
社区贡献组   /  发表于:2015-12-21 15:21:00
8#
回复 7楼dec691028的帖子

在C1Chart for wpf里,可以使用DataSeries.PlotElementLoaded事件去重写图表元素的默认样式和行为。
您可以参考在我们的产品博客:
http://blog.gcpowertools.com.cn/ ... taPointCustom1.aspx

还有一种定义color palettes的方法,参考:http://blog.gcpowertools.com.cn/ ... t_ColorPalette.aspx
请点击评分,对我的服务做出评价!  5分为非常满意!

葡萄城控件服务团队

官方网站: http://www.gcpowertools.com.cn
回复 使用道具 举报
12下一页
您需要登录后才可以回帖 登录 | 立即注册
返回顶部