2013-05-31 44 views
0

我有一個TChart組件,帶有一個Fastline系列和一個ColorBand工具。在形式上,我也有一個啓動計時器的按鈕。在每次定時器過去的事件中,我生成2048個隨機數據樣本並更新Fasline系列。當我啓動計時器時,TChart上沒有動畫!它似乎隨機工作,雖然...而且,當我隱藏和顯示錶單(通過最小化/最大化,或通過tChart1.Hide()/ tChart1.Show()),然後動畫開始再次工作,或者當我在啓動定時器之前拖動其中一條ColorBand線,然後動畫工作。但是當我首先啓動計時器時動畫不起作用。而且,此外,當它不起作用時,TChart似乎被凍結,即,它不響應任何鼠標命令,例如平移或縮放。下面是一些代碼:TChart控制凍結

在我form.designer.cs:

partial class Form1 
{ 
    /// <summary> 
    /// Required designer variable. 
    /// </summary> 
    private System.ComponentModel.IContainer components = null; 

    /// <summary> 
    /// Clean up any resources being used. 
    /// </summary> 
    /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> 
    protected override void Dispose(bool disposing) 
    { 
     if (disposing && (components != null)) 
     { 
      components.Dispose(); 
     } 
     base.Dispose(disposing); 
    } 

    #region Windows Form Designer generated code 

    /// <summary> 
    /// Required method for Designer support - do not modify 
    /// the contents of this method with the code editor. 
    /// </summary> 
    private void InitializeComponent() 
    { 
     this.button1 = new System.Windows.Forms.Button(); 
     this.tChart1 = new Steema.TeeChart.TChart(); 
     this.checkBox1 = new System.Windows.Forms.CheckBox(); 
     this.SuspendLayout(); 
     // 
     // button1 
     // 
     this.button1.BackColor = System.Drawing.SystemColors.Control; 
     this.button1.Location = new System.Drawing.Point(12, 12); 
     this.button1.Name = "button1"; 
     this.button1.Size = new System.Drawing.Size(60, 23); 
     this.button1.TabIndex = 1; 
     this.button1.Text = "Start"; 
     this.button1.UseVisualStyleBackColor = false; 
     this.button1.Click += new System.EventHandler(this.button1_Click); 
     // 
     // tChart1 
     // 
     // 
     // 
     // 
     // 
     // 
     // 
     this.tChart1.Axes.Depth.LabelsAsSeriesTitles = true; 
     // 
     // 
     // 
     this.tChart1.Axes.DepthTop.LabelsAsSeriesTitles = true; 
     this.tChart1.Location = new System.Drawing.Point(12, 41); 
     this.tChart1.Name = "tChart1"; 
     this.tChart1.Size = new System.Drawing.Size(789, 318); 
     this.tChart1.TabIndex = 2; 
     // 
     // checkBox1 
     // 
     this.checkBox1.AutoSize = true; 
     this.checkBox1.Location = new System.Drawing.Point(78, 16); 
     this.checkBox1.Name = "checkBox1"; 
     this.checkBox1.Size = new System.Drawing.Size(49, 17); 
     this.checkBox1.TabIndex = 3; 
     this.checkBox1.Text = "Drag"; 
     this.checkBox1.UseVisualStyleBackColor = true; 
     this.checkBox1.Click += new System.EventHandler(this.checkBox1_Click); 
     // 
     // Form1 
     // 
     this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 
     this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 
     this.ClientSize = new System.Drawing.Size(823, 371); 
     this.Controls.Add(this.checkBox1); 
     this.Controls.Add(this.tChart1); 
     this.Controls.Add(this.button1); 
     this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D; 
     this.Name = "Form1"; 
     this.Text = "Form1"; 
     this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Form1_FormClosing); 
     this.SizeChanged += new System.EventHandler(this.Form1_SizeChanged); 
     this.ResumeLayout(false); 
     this.PerformLayout(); 

    } 

    #endregion 

    private System.Windows.Forms.Button button1; 
    private Steema.TeeChart.TChart tChart1; 
    private System.Windows.Forms.CheckBox checkBox1; 
} 

然後在我的form.cs:

public partial class Form1 : Form 
{ 
    System.Timers.Timer timer; 
    private Steema.TeeChart.Tools.ColorBand tool; 
    Steema.TeeChart.Styles.FastLine primaryLine; 
    double w = 0; 
    bool enabled = false; 

    public Form1() 
    { 
     InitializeComponent(); 
     initPrimaryGraph(); 
     initTool(); 

     timer = new System.Timers.Timer(); 
     timer.Elapsed += new ElapsedEventHandler(timer_Elapsed); 
     timer.Interval = 50; 
     timer.Stop(); 
    } 

    private void timer_Elapsed(object sender, ElapsedEventArgs e) 
    { 
     Random rnd = new Random(); 
     for (int i = 0; i < 2048; i++) 
     { 
      primaryLine.XValues[i] = i; 
      primaryLine.YValues[i] = 20 + rnd.Next(50); 
     } 
     primaryLine.BeginUpdate(); 
     primaryLine.EndUpdate(); 
    } 

    private void initTool() 
    { 
     tool = new Steema.TeeChart.Tools.ColorBand(); 
     tChart1.Tools.Add(tool); 
     tool.Axis = tChart1.Axes.Bottom; 
     tool.Start = 300; 
     tool.End = 400; 
     tool.Brush.Color = Color.Yellow; 
     tool.Pen.Color = Color.Blue; 
     tool.Pen.Width = 2; 
     tool.Transparency = 60; 

     tool.StartLine.AllowDrag = true; 
     tool.StartLine.DragRepaint = true; 
     tool.ResizeStart = true; 
     tool.StartLine.DragLine += new EventHandler(StartLine_DragLine); 

     tool.EndLine.AllowDrag = true; 
     tool.EndLine.DragRepaint = true; 
     tool.ResizeEnd = true; 
     tool.EndLine.DragLine += new EventHandler(EndLine_DragLine); 
    } 

    void StartLine_DragLine(object sender, EventArgs e) 
    { 
     if (enabled) 
     { 
      tool.End = tool.Start + w; 
     } 
    } 

    void EndLine_DragLine(object sender, EventArgs e) 
    { 
     if (enabled) 
     { 
      tool.Start = tool.End - w; 
     } 
    } 

    private void initPrimaryGraph() 
    { 
     tChart1.Header.Visible = true; 

     tChart1.Axes.Bottom.Automatic = false; 
     tChart1.Axes.Bottom.Minimum = 0; 
     tChart1.Axes.Bottom.Maximum = 2048; 
     tChart1.Axes.Bottom.Labels.Font.Color = Color.White; 
     tChart1.Axes.Bottom.Grid.Visible = false; 

     tChart1.Axes.Left.Automatic = false; 
     tChart1.Axes.Left.Minimum = 0; 
     tChart1.Axes.Left.Maximum = 300; 
     tChart1.Axes.Left.Labels.Font.Color = Color.White; 

     tChart1.Aspect.View3D = false; 

     tChart1.Walls.Back.Visible = false; 
     tChart1.Walls.Bottom.Visible = false; 
     tChart1.Walls.Left.Visible = false; 
     tChart1.Walls.Right.Visible = false; 

     tChart1.Legend.Visible = false; 
     tChart1.BackColor = Color.Black; 
     tChart1.Panel.Visible = false; 

     //PRIMARY GRAPH..... 
     primaryLine = new Steema.TeeChart.Styles.FastLine(); 
     tChart1.Series.Add(primaryLine); 
     Random rnd = new Random(); 
     for (int i = 0; i < 2048; i++) 
     { 
      double x = i; 
      double y = 20 + rnd.Next(50); 
      primaryLine.Add(x, y); 
     } 
     primaryLine.LinePen.Style = System.Drawing.Drawing2D.DashStyle.Solid; 
     primaryLine.LinePen.Color = Color.White; 
     primaryLine.LinePen.Width = 1; 
     primaryLine.VertAxis = Steema.TeeChart.Styles.VerticalAxis.Left; 
    } 

    private void tool_DragLine(object sender, EventArgs e) 
    { 
     Steema.TeeChart.Tools.ColorLine t = sender as Steema.TeeChart.Tools.ColorLine; 
     this.Text = t.Value.ToString(); 
    } 

    private void button1_Click(object sender, EventArgs e) 
    { 
     if (timer.Enabled) 
     { 
      timer.Stop(); 
      button1.Text = "Start"; 
     } 
     else 
     { 
      timer.Start(); 
      button1.Text = "Stop"; 
     } 
    } 

    private void Form1_FormClosing(object sender, FormClosingEventArgs e) 
    { 
     timer.Stop(); 
    } 

    private void checkBox1_Click(object sender, EventArgs e) 
    { 
     if (checkBox1.Checked) 
     { 
      w = tool.End - tool.Start; 
     } 
     enabled = checkBox1.Checked; 
    } 
} 

我有另外一個問題。我想創建一個TeeChart組件的黑盒子實現,通過編寫一個自定義API(一個自定義用戶控件)來公開特定的功能,以便我可以在其他項目中使用它,以便我的一個或多個同事可以工作在他們的項目中使用它。我應該購買TeeChart的哪個版本/許可證,這將允許我將TeeChart功能包裝在可用於各種項目/計算機的自定義組件/ dll中?

在此先感謝:-)

回答

0

我有一個TChart組件,具有快繩系列和色帶 工具。在形式上,我也有一個啓動計時器的按鈕。在每個 計時器過去的事件中,我生成2048個隨機數據樣本並更新了Fasline系列的 。當我啓動計時器時,TChart上沒有動畫 !它似乎隨機工作,雖然...並且,當我隱藏並顯示錶格(通過最小化/最大化,或者通過tChart1.Hide()/ tChart1.Show()) ,則動畫再次開始工作 ,或者當我在啓動 定時器之前拖動ColorBand行之一,然後動畫工作。但是當我首先啓動計時器時,動畫不起作用。另外,當它不起作用時,TChart似乎被凍結,即,它不響應任何諸如平移或縮放之類的鼠標命令。這裏是一些代碼:

我已經修改了一些你的代碼,現在它在我的最終工作。看下:

Timer timer; 
    private Steema.TeeChart.Tools.ColorBand tool; 
    Steema.TeeChart.Styles.FastLine primaryLine; 
    double w = 0; 
    bool enabled = false; 

    public Form1() 
    { 
     InitializeComponent(); 
     initPrimaryGraph(); 
     initTool(); 

     timer = new Timer(); 
     //Enable Timer 
     timer.Enabled = true; 
     timer.Interval = 50; 
     timer.Tick += timer_Tick; 
    } 

    void timer_Tick(object sender, EventArgs e) 
    { 

     AnimateSeries(tChart1); 
    } 

    private void AnimateSeries(TChart tChart) 
    { 
     Random rnd = new Random(); 
     tChart.AutoRepaint = false; 
     primaryLine.BeginUpdate(); 
     foreach (Steema.TeeChart.Styles.Series s in tChart.Series) 
     {   
      for (int i = 0; i < 2048; i++) 
      { 
       primaryLine.XValues[i] = i; 
       primaryLine.YValues[i] = 20 + rnd.Next(50); 
      } 

     } 

     tChart.AutoRepaint = true; 
     primaryLine.EndUpdate(); 
    } 
    private void initTool() 
    { 
     tool = new Steema.TeeChart.Tools.ColorBand(); 
     tChart1.Tools.Add(tool); 
     tool.Axis = tChart1.Axes.Bottom; 
     tool.Start = 300; 
     tool.End = 400; 
     tool.Brush.Color = Color.Yellow; 
     tool.Pen.Color = Color.Blue; 
     tool.Pen.Width = 2; 
     tool.Transparency = 60; 

     tool.StartLine.AllowDrag = true; 
     tool.StartLine.DragRepaint = true; 
     tool.ResizeStart = true; 
     tool.StartLine.DragLine += new EventHandler(StartLine_DragLine); 

     tool.EndLine.AllowDrag = true; 
     tool.EndLine.DragRepaint = true; 
     tool.ResizeEnd = true; 
     tool.EndLine.DragLine += new EventHandler(EndLine_DragLine); 
    } 

    void StartLine_DragLine(object sender, EventArgs e) 
    { 
     if (enabled) 
     { 
      tool.End = tool.Start + w; 
     } 
    } 

    void EndLine_DragLine(object sender, EventArgs e) 
    { 
     if (enabled) 
     { 
      tool.Start = tool.End - w; 
     } 
    } 

    private void initPrimaryGraph() 
    { 
     tChart1.Header.Visible = true; 
     tChart1.Aspect.View3D = false; 

     tChart1.Walls.Back.Visible = false; 
     tChart1.Walls.Bottom.Visible = false; 
     tChart1.Walls.Left.Visible = false; 
     tChart1.Walls.Right.Visible = false; 

     tChart1.Legend.Visible = false; 
     tChart1.BackColor = Color.Black; 
     tChart1.Panel.Visible = false; 

     //PRIMARY GRAPH..... 
     primaryLine = new Steema.TeeChart.Styles.FastLine(); 
     tChart1.Series.Add(primaryLine); 
     Random rnd = new Random(); 
     for (int i = 0; i < 2048; i++) 
     { 
      double x = i; 
      double y = 20 + rnd.Next(50); 
      primaryLine.Add(x, y); 
     } 
     primaryLine.LinePen.Style = System.Drawing.Drawing2D.DashStyle.Solid; 
     primaryLine.LinePen.Color = Color.White; 
     primaryLine.LinePen.Width = 1; 
     //AXES 
     tChart1.Axes.Bottom.Automatic = false; 
     tChart1.Axes.Bottom.Minimum = primaryLine.XValues.Minimum; 
     tChart1.Axes.Bottom.Maximum = primaryLine.XValues.Maximum; 
     tChart1.Axes.Bottom.Increment = 200; 
     tChart1.Axes.Bottom.Labels.Font.Color = Color.White; 
     tChart1.Axes.Bottom.Grid.Visible = false; 
     tChart1.Axes.Left.Automatic = false; 
     tChart1.Axes.Left.Minimum = 0; 
     tChart1.Axes.Left.Maximum = 300; 

     tChart1.Axes.Left.Labels.Font.Color = Color.White; 
     primaryLine.VertAxis = Steema.TeeChart.Styles.VerticalAxis.Left; 
     tChart1.Draw(); 
    } 

    private void tool_DragLine(object sender, EventArgs e) 
    { 
     Steema.TeeChart.Tools.ColorLine t = sender as Steema.TeeChart.Tools.ColorLine; 
     this.Text = t.Value.ToString(); 
    } 

    private void button1_Click(object sender, EventArgs e) 
    { 
     if (timer.Enabled) 
     { 
      timer.Stop(); 
      button1.Text = "Start"; 
     } 
     else 
     { 
      timer.Start(); 
      button1.Text = "Stop"; 
     } 
    } 

    private void Form1_FormClosing(object sender, FormClosingEventArgs e) 
    { 
     timer.Stop(); 
    } 

正如你在代碼中看到我已經改變定時器的其他我認爲更合適的類型。你能告訴我們,如果以前的代碼按照你的預期工作?

我還有一個問題。我想創建一個TeeChart組件的黑盒子實現 ,通過編寫一個自定義API(一個自定義用戶控件)來公開特定的功能,以便我可以在其他項目中使用它 ,以便我的一個或多個同事在工作中, 可以在他們的項目中使用它。什麼版本/ TeeChart許可證,我應該 購買,這將允許我包裝TeeChart功能在 自定義組件/ dll,可用於各種 項目/計算機?

TeeChart可能會被另一個發佈teeChart的某些特性的設計時組件(dll)重用。請不要在設計時重用tee組件的機器也應該安裝TeeChart Developer許可證。

我希望能幫上忙。

謝謝,

+0

謝謝,我會嘗試你的建議,並在稍後完成後給你反饋:-) – user1980088