
public partial class Form1 : Form
{
private PointPairList list = new PointPairList();
public Form1()
{
InitializeComponent();
GraphPane myPane = zedGraphControl1.GraphPane;
myPane.AddCurve("曲线1", list, Color.Blue, SymbolType.None);
//設定標題
myPane.Title.Text = "即時趨勢圖";
//設定X軸標題
myPane.XAxis.Title.Text = "時間";
//設定X軸標題
myPane.YAxis.Title.Text = "電壓";
timer1.Interval = 1000;
timer1.Enabled = true;
timer1.Start();
myPane.YAxis.Scale.Min = -10;
myPane.YAxis.Scale.Max = 10;
myPane.XAxis.Scale.Format = "HH:mm:ss";
myPane.XAxis.Type = ZedGraph.AxisType.DateAsOrdinal;
myPane.XAxis.Scale.Min = 0;
myPane.XAxis.Scale.Max = 100;
myPane.XAxis.MajorGrid.IsVisible = true;
myPane.YAxis.MajorGrid.IsVisible = true;
zedGraphControl1.IsShowPointValues = true;
// Make sure the Graph gets redrawn
zedGraphControl1.Invalidate();
}
Random Rnd = new Random();
private void timer1_Tick(object sender, EventArgs e)
{
double Value = Rnd.NextDouble() * 18 - 9;
double x = (double)new XDate(DateTime.Now);
list.Add(x, Value);
zedGraphControl1.AxisChange();
zedGraphControl1.Invalidate();
if (list.Count >= 100)
{
list.RemoveAt(0);
}
}
}
沒有留言:
張貼留言