从超声心动图动态创建图表

时间:2015-02-18 12:01:49

标签: c# winforms

如何从超声心动图动态

等行创建图表

我试试这个:

Graphics gr = this.CreateGraphics();
            Pen p = new Pen(System.Drawing.Color.Blue, 3.0f);
            int y = 15;
            for (int i = 1; i < 800; i = i + 10)
            {
                gr.DrawLine(p, i, 500, i, y);
                if (i < 400)
                    y = y + 5;
                else
                    y = y - 5;
            }

我应该像超声心动图一样有信息流

the X -> is the time
the y -> is the value

感谢

1 个答案:

答案 0 :(得分:0)

这可能会给你一个想法 。 enter image description here

使用计时器生成随机Y值的示例应用程序。 图表绘制在pictureBox上。并设置一个计时器来频繁刷新pictureBox。

 public partial class Form1 : Form
{
    Timer timer = new Timer();
    int curX = 0;
    Timer valueInsertingTimer = new Timer();
    public Form1()
    {
        InitializeComponent();
        pictureBox1.Paint += pictureBox1_Paint;
        timer.Interval = 10;
        timer.Tick += timer_Tick;
        timer.Start();

        valueInsertingTimer.Interval = 30;
        valueInsertingTimer.Tick += valueInsertingTimer_Tick;
        valueInsertingTimer.Start();
    }


    void valueInsertingTimer_Tick(object sender, EventArgs e)
    {
        Random rnd = new Random();
        int num = rnd.Next(80);
        addY(num);
    }

    void addY(int val)
    {
        if (Ys.Count > 0)
        {
            int lastY = Ys[Ys.Count - 1];
            if (val > lastY)
            {
                for (int i = lastY; i < val; i++)
                {
                    Ys.Add(i);
                    Xs.Add(curX += 1);
                }
            }
            else if (val < lastY)
            {
                for (int i = lastY; i > val; i--)
                {
                    Ys.Add(i);
                    Xs.Add(curX += 1);
                }
            }
            else
            {
                Xs.Add(curX += 1);
                Ys.Add(val);
            }
        }
        else
        {
            Ys.Add(1);
            Xs.Add(curX += 1);
        }
        if (Xs.Count > pictureBox1.Width)
        {
            Xs.RemoveAt(0);
            Ys.RemoveAt(0);
            difference++;
        }

    }

    int difference = 0;

    void timer_Tick(object sender, EventArgs e)
    {
        pictureBox1.Refresh();
    }

    List<int> Xs = new List<int>();
    List<int> Ys = new List<int>();

    void pictureBox1_Paint(object sender, PaintEventArgs e)
    {
        for (int i = 0; i < Xs.Count; i++)
        {
            e.Graphics.FillRectangle(Brushes.Black, Xs[i] - difference, pictureBox1.Height - Ys[i], 1, 1);
        }
    }

}
相关问题