C#画动态折线图
如题,像任务管理器那样CPU使用率的折线图,如何画?好像用GDI+编程在一个控件上创建画刷画吗?求思路,求代码!
using System; using System.Collections.Generic; using using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace DrawArc { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private Point[] pArr = new Point[60]; //点数 private void InitpArr() //初始化各点 { int step = 0; for (int i = 0; i < 60; i++) { pArr[i].X = step; pArr[i].Y = 100; step += 10; } } private void ReFpArr(int y) //更新点 { for (int i = 0; i < 59; i++) { pArr[i].Y = pArr[i + 1].Y; } pArr[59].Y = y; } private int NewData() { Random rd = new Random(); return rd.Next(0, 100); } private void DrawLabel() { Graphics g = this.imageLabel.CreateGraphics(); g.Clear(Color.Black); Pen p = new Pen(Color.Green); g.DrawLines(p, pArr); } private void timer1_Tick(object sender, EventArgs e) { int i = NewData(); ReFpArr(100 - i); DrawLabel(); } private void Form1_Load(object sender, EventArgs e) { timer1.Interval = 1000; timer1.Enabled = true; InitpArr(); } } }