2013-03-20 80 views
0

我有16個圖[最大值],每個圖中有4條快速線。在每幅圖中,3條快速線表示最小值,最大值和理想值。第四條fastline是來自硬件的實際值。我必須運行18,000個樣本的測試。因此,前3條快速線已經繪製好,當開關打開並且數據進入時,將繪製第4條快速線。爲了繪製第四行,我使用方法Series4.Add(actualvalue,「」,color.red)。 這裏是問題所在。每次在第4行繪製樣本。圖表必須刷新才能查看該樣本的繪圖。還重繪了其他3條快速線,每條18000個樣本。所以它重繪了很多樣本​​而沒有再次使用。我只需要畫第四條快速線。 我不能使用數組來填充值,然後將其分配爲fastline的源,因爲我事先沒有任何值。我嘗試了series4.repaint()方法和series4.refreshseries()方法,但實際上並沒有重繪第4個系列。我們必須刷新整個圖表。因此,由於每條快速線[18,000]中有大量樣本,並且有4條快速線和總共16個這樣的圖,因此它會降低性能。我已經完成 Series4.AutoRepaint = false,Series4.DrawAllPoints = false; Series4.XValues.Order = ValueListOrder.None,Series4.YValues.Order = ValueListOrder.None如何提高tchart refresh()的速度?

有沒有什麼辦法可以提高性能? 謝謝。

回答

2

我做了一個簡單的代碼,其中我用4個FastLines添加了4個圖表,每個fastline使用18000個點,使用表添加一個初始化值,並在更新了Series4的值之後。性能對於我正在繪製的數值有好處:

 public Form1() 
    { 
     InitializeComponent(); 
     InitializeChart(); 
    } 

    // Steema.TeeChart.Styles.FastLine Series1; 

    Timer timer1, timer2,timer3, timer4; 
    Random r; 
    DateTime dt; 
    DateTime[] Xvalues1; 
    double[] Yvalues1; 
    Steema.TeeChart.TChart tChart1, tChart2, tChart3,tChart4; 
    private void InitializeChart() 
    { 

     tChart1 = new TChart(); 
     tChart2 = new TChart(); 
     tChart3 = new TChart(); 
     tChart4 = new TChart(); 
     this.Controls.Add(tChart1); 
     this.Controls.Add(tChart2); 
     this.Controls.Add(tChart3); 
     this.Controls.Add(tChart4); 

     //Initialize Locations and size 

     this.Width = 908; 
     this.Height = 600; 

     //Location 
     tChart1.Left = 12; 
     tChart1.Top = 53; 
     tChart2.Left = 468; 
     tChart2.Top = 53; 
     tChart3.Left = 12; 
     tChart3.Top = 318; 
     tChart4.Left = 468; 
     tChart4.Top = 318; 

     //Size 
     tChart1.Width = 373; 
     tChart1.Height = 236; 
     tChart2.Width = 373; 
     tChart2.Height = 236; 
     tChart3.Width = 373; 
     tChart3.Height = 236; 
     tChart4.Width = 373; 
     tChart4.Height = 236;  

     tChart1.Aspect.View3D = false; 
     tChart2.Aspect.View3D = false; 
     tChart3.Aspect.View3D = false; 
     tChart4.Aspect.View3D = false; 

     tChart1.Legend.Visible = false; 
     tChart2.Legend.Visible = false; 
     tChart3.Legend.Visible = false; 
     tChart4.Legend.Visible = false; 


     tChart1.Panel.Gradient.Visible = false; 
     tChart2.Panel.Gradient.Visible = false; 
     tChart3.Panel.Gradient.Visible = false; 
     tChart4.Panel.Gradient.Visible = false; 


     tChart1.Axes.Bottom.AxisPen.Visible = false; 
     tChart2.Axes.Bottom.AxisPen.Visible = false; 
     tChart3.Axes.Bottom.AxisPen.Visible = false; 
     tChart4.Axes.Bottom.AxisPen.Visible = false; 

     tChart1.Axes.Left.AxisPen.Visible = false; 
     tChart2.Axes.Left.AxisPen.Visible = false; 
     tChart3.Axes.Left.AxisPen.Visible = false; 
     tChart4.Axes.Left.AxisPen.Visible = false; 

     //Series 
     tChart1.AutoRepaint = false; 
     tChart2.AutoRepaint = false; 
     tChart3.AutoRepaint = false; 
     tChart4.AutoRepaint = false; 

     for (int i = 0; i < 4; i++) 
     { 
      new Steema.TeeChart.Styles.FastLine(tChart1.Chart); 
      new Steema.TeeChart.Styles.FastLine(tChart2.Chart); 
      new Steema.TeeChart.Styles.FastLine(tChart3.Chart); 
      new Steema.TeeChart.Styles.FastLine(tChart4.Chart); 

      tChart1[i].XValues.DateTime=true; 
      tChart2[i].XValues.DateTime = true; 
      tChart3[i].XValues.DateTime = true; 
      tChart4[i].XValues.DateTime = true; 
      InitialDataSeries(tChart1[i]); 
      InitialDataSeries(tChart2[i]); 
      InitialDataSeries(tChart3[i]); 
      InitialDataSeries(tChart4[i]); 

     } 

     //Axes labels 
     tChart1.Axes.Bottom.Labels.DateTimeFormat = "dd/MM"; 
     tChart1.Axes.Bottom.Labels.Angle = 90; 
     tChart2.Axes.Bottom.Labels.DateTimeFormat = "dd/MM"; 
     tChart2.Axes.Bottom.Labels.Angle = 90; 
     tChart3.Axes.Bottom.Labels.DateTimeFormat = "dd/MM"; 
     tChart3.Axes.Bottom.Labels.Angle = 90; 
     tChart4.Axes.Bottom.Labels.DateTimeFormat = "dd/MM"; 
     tChart4.Axes.Bottom.Labels.Angle = 90; 
     tChart1.AutoRepaint = true; 
     tChart2.AutoRepaint = true; 
     tChart3.AutoRepaint = true; 
     tChart4.AutoRepaint = true; 
     tChart1.Refresh(); 
     tChart2.Refresh(); 
     tChart3.Refresh(); 
     tChart4.Refresh(); 

     //Timer 
     timer1 = new Timer(); 
     timer1.Start(); 
     timer1.Interval = 100; 
     timer1.Tick += new EventHandler(timer1_Tick); 

    } 

    void timer1_Tick(object sender, EventArgs e) 
    { 
     //See the chart data updated. 
     tChart1[0].Visible = false; 
     tChart1[1].Visible = false; 
     tChart1[2].Visible = false; 
     PopulateSeries(tChart1[3]); 
     PopulateSeries(tChart2[3]); 
     PopulateSeries(tChart3[3]); 
     PopulateSeries(tChart4[3]); 

    } 
    private void PopulateSeries(Steema.TeeChart.Styles.Series Series1) 
    { 
     r = new Random(); 
     dt = DateTime.Now; 
     tChart1.AutoRepaint = false; 
     tChart2.AutoRepaint = false; 
     tChart3.AutoRepaint = false; 
     tChart4.AutoRepaint = false; 
     // show only 50 points - delete the rest 
     while (Series1.Count > 10000) 
     { 
      Series1.Delete(0); 

     } 
     if (Series1.Count > 10000) 
     { 
      Series1.Delete(0); 

     } 
     else 
     { 
      for (int t = 0; t < 100; t++) 
      { 

       Series1.Add(dt, r.Next(1000)); 
       dt = dt.AddSeconds(15); 
      } 
     } 
     tChart1.AutoRepaint = true; 
     tChart2.AutoRepaint = true; 
     tChart3.AutoRepaint = true; 
     tChart4.AutoRepaint = true; 
     tChart1.Refresh(); 
     tChart2.Refresh(); 
     tChart3.Refresh(); 
     tChart4.Refresh(); 
    } 

    private void InitialDataSeries(Steema.TeeChart.Styles.Series Series1) 
    {  
     //Arrays 
     dt = DateTime.Now; 
     r = new Random(); 
     Xvalues1 = new DateTime[18000]; 
     Yvalues1 = new double[18000]; 
     (Series1 as Steema.TeeChart.Styles.FastLine).DrawAllPoints = false; 
     for (int j = 0; j < 18000; j++) 
     { 
      Xvalues1[j] = dt; 
      dt = dt.AddSeconds(15); 
      Yvalues1[j] = r.Next(1000); 
     } 

     Series1.Add(Xvalues1, Yvalues1); 
    } 

您能告訴我們它是否對您有幫助嗎?另一方面,如果我的代碼無法幫助您,我建議您使用TeeChartDirect2D,這對於DSP實時應用程序所需的高速數據吞吐量來說非常理想。請參閱白皮書Boosting graphics-rendering performance in Windows Forms,以獲得更詳細的信息。

謝謝,

+0

謝謝,但我不能讓其他3行看不見。我希望能夠以最小最大值和理想範圍實時查看第四條線的位置。所以在使它們看不見之後,它以極佳的速度繪製。但我不能隱藏其他3行。所以,我不能做fastline.visible = false和fastline.active = false。令人驚訝的活躍也隱藏了快速線。所以看起來像主動和可見服務於相同的目的。有沒有辦法可以使用fastline.draw(),fastline.repaint(),fastline.refreshseries()更新第4行? – 2013-03-21 04:52:03

+0

我也嘗試下載direct2d演示。 graphicscontrol.dll缺少winforms應用程序。搜索了zip文件,但沒有像那樣的dll文件,也就是說Matrix3x2不存在。 – 2013-03-21 05:28:40

+0

也是private void PopulateSeries(Steema.TeeChart.Styles.Series Series1)和private void InitialDataSeries(Steema.TeeChart.Styles.Series Series1)。不應該是Steema.TeeChart.Styles.Fastline,而不是Steema.TeeChart.Styles.Series – 2013-03-21 05:48:16