我有一个 TChart 组件,带有一个 Fastline 系列和一个 ColorBand 工具。在表单上,我还有一个启动计时器的按钮。在每个计时器经过事件中,我都会生成 2048 个随机数据样本并更新 Fasline 系列。当我启动计时器时,TChart 上没有动画!不过,它似乎是随机工作的......而且,当我隐藏和显示表单(通过最小化/最大化,或通过 tChart1.Hide()/tChart1.Show())时,动画再次开始工作,或者当我在启动计时器之前拖动其中一条 ColorBand 线,然后动画就起作用了。但是当我首先启动计时器时动画不起作用。而且,此外,当它不工作时,TChart 似乎被冻结,即,ot 不响应任何鼠标命令,例如平移或缩放。这是一些代码:
在我的 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;
}
}
我有另一个问题。我想通过编写自定义 API(自定义用户控件)来创建 TeeChart 组件的黑盒实现以公开特定功能,以便我可以在其他项目中使用它,并且我的一个或多个同事可以在他们的项目中使用它。我应该购买什么版本/许可证的 TeeChart 可以让我将 TeeChart 功能包装在可用于各种项目/计算机的自定义组件/dll 中?
提前致谢 :-)