2014-09-26 84 views
1

我使用.NET Winform版本teechart 4.1.2012.1032。放大縮小採樣圖

我修改了您提供的示例。 「Extended \ Reducing Number of Points \ DownSampling Additions」 但是,當我放大圖表時,fastline的標記計數不是100,downSampling.DisplayedPointCount。 我該如何解決它?

private void InitializeChart() 
    { 
     this.cursorTool1 = new Steema.TeeChart.Tools.CursorTool();// 
     this.tChart1.Tools.Add(this.cursorTool1);// 
     this.cursorTool1.FollowMouse = true;// 
     this.cursorTool1.Style = Steema.TeeChart.Tools.CursorToolStyles.Vertical;// 
     this.cursorTool1.Change += new Steema.TeeChart.Tools.CursorChangeEventHandler(this.cursorTool1_Change);// 

     CreateArrays(); 
     tChart1.Aspect.View3D = false; 
     tChart1.Zoom.Direction = ZoomDirections.Both;//.Horizontal;// 
     tChart1.Series.Add(points = new Steema.TeeChart.Styles.Points()); 
     tChart1.Series.Add(fastLine = new Steema.TeeChart.Styles.FastLine()); 

     downSampling = new Steema.TeeChart.Functions.DownSampling(tChart1.Chart); 
     points.Add(xValues, yValues); 
     points.Active = false; 

     downSampling.DisplayedPointCount = 100; 
     downSampling.Method = Steema.TeeChart.Functions.DownSamplingMethod.MinMaxFirstLast;// Null; 
     fastLine.TreatNulls = Steema.TeeChart.Styles.TreatNullsStyle.DoNotPaint; 
     fastLine.DataSource = points; 
     fastLine.Function = downSampling; 

     this.tChart1.Axes.Custom.Add(new Steema.TeeChart.Axis(this.tChart1.Chart));// 
     this.tChart1[1].CustomVertAxis = this.tChart1.Axes.Custom[0];// 
     this.tChart1[0].CustomVertAxis = this.tChart1.Axes.Custom[0];// 

     this.fastLine.Marks.Visible = true;// 
    } 

    private void CreateArrays() 
    { 
     int length = 2600000; 

     xValues = new Nullable<double>[length]; 
     yValues = new Nullable<double>[length]; 

     Random rnd = new Random(); 
     for (int i = 0; i < length; i++) 
     { 
      xValues[i] = i; 
      yValues[i] = i; 
     } 
    } 

    private void tChart1_Zoomed(object sender, EventArgs e) 
    { 
     tChart1[1].CheckDataSource(); //series 1 is the function series 
    } 

回答

0

DisplayedPointCount指定了DownSampling函數應該繪製多少個點,並將該數字顯示爲最大點數。由於I explained here,您可能需要將它與Tolerance屬性結合使用以獲得您期望的結果。所以,你可以這樣做:

public partial class Form1 : Form 
    { 
    public Form1() 
    { 
     InitializeComponent(); 
     InitializeChart(); 
    } 

    private void InitializeChart() 
    { 
     //tChart1.Dock = DockStyle.Fill; 
     tChart1.Aspect.View3D = false; 
     tChart1.Zoomed += tChart1_Zoomed; 

     Steema.TeeChart.Styles.Points points1 = new Steema.TeeChart.Styles.Points(tChart1.Chart); 

     Random y = new Random(); 
     for (int i = 0; i < 10000; i++) 
     { 
     points1.Add(DateTime.Now.AddHours(i), y.Next()); 
     } 

     points1.XValues.DateTime = true; 
     points1.Pointer.HorizSize = 1; 
     points1.Pointer.VertSize = 1; 

     Steema.TeeChart.Functions.DownSampling downSampling1 = new Steema.TeeChart.Functions.DownSampling(tChart1.Chart); 
     downSampling1.Method = Steema.TeeChart.Functions.DownSamplingMethod.Average; 
     downSampling1.Tolerance = 100; 
     downSampling1.DisplayedPointCount = Convert.ToInt32(downSampling1.Tolerance * 4); 

     Steema.TeeChart.Styles.Line line1 = new Steema.TeeChart.Styles.Line(tChart1.Chart); 
     line1.Function = downSampling1; 
     line1.DataSource = points1; 
     line1.Marks.Visible = true; 
     line1.Marks.Style = MarksStyles.PointIndex; 

     UpdateTitle(); 
    } 

    void tChart1_Zoomed(object sender, EventArgs e) 
    { 
     tChart1[1].CheckDataSource(); 
     UpdateTitle(); 
    } 

    private void UpdateTitle() 
    { 
     tChart1.Header.Text = (tChart1[1].Function as Steema.TeeChart.Functions.DownSampling).DisplayedPointCount.ToString(); 
    } 
    } 
+0

我知道DisplayedPointCount的含義。如果我將DisplayedPointCount設置爲100,則繪製100個點。但是當我放大時,我認爲數值100必須在Axes.Bottom.Minimum和Maximum之間重繪。但結果沒有。我該如何解決它?這個錯誤?請給我一個關於這種情況的示例代碼(在縮減採樣功能的情況下放大/縮小)謝謝。 – 2014-10-01 00:04:10

+0

@DugSungKim恐怕我沒有足夠清楚地解釋我自己。 DisplayedPointCount是將顯示的最大點數,但並不意味着會達到此值。無論如何,我只是用解決方案更新了我的答案。 – 2014-10-01 10:07:29

+0

謝謝你的回答。但是,如果points1.Active爲false,則代碼中顯示的不正確。在我的情況下,Points1.Active必須是錯誤的,因爲如果不是這樣,那麼將顯示如此多的數據,並且圖表性能不會太好。還有其他解決方案嗎? – 2014-10-02 03:57:43