本帖最后由 fishrd 于 2010-09-02 22:46:29 编辑

解决方案 »

  1.   

    给你个简单代码,希望对你有帮助。List<Point> dataList = new List<Point>();
            //采集数据,采集时间对应的值。时间休整成整数,可以是开始时间的增量s
            void GetData(int time, int value)
            {
                dataList.Add(new Point(time, value));
            }        //在重画事件中将数据画出折线图
            private void pictureBox1_Paint(object sender, PaintEventArgs e)
            {
                for (int i = 0; i < dataList.Count - 1; i++)
                {
                    Point p1 = dataList[i];
                    Point p2 = dataList[i + 1];
                    e.Graphics.DrawLine(new Pen(Color.Black), p1, p2);
                }
            }
      

  2.   

    这没啥难度啊,就是首先创建X/Y坐标轴,(我看你坐标轴创建好了),确定Point[] p = new Point[dt.Rows.Count]; p[i].X = ....p[i].Y = .........最后g.DrawLines(new Pen(Color.red),  p);就OK了。。
      

  3.   

    你只要确定好了Point的X和Y,一连就可以了,主要是确定Point的X和Y
      

  4.   


    int count = dt.Rows.Count;
    Point[] p = new Point[count];
                        for (int i = 0; i < count ; i++) //定义曲线转折点
                        {
                            p[i].X = picturebox1.Width/ count * i;
                            p[i].Y = picturebox1.Height - Convert.ToInt32((Convert.ToDouble(dt.Rows[i][0]) * picturebox1.Height/10)); 
                        }
                        g.DrawLines(new Pen(Color.red),  p);
                        //绘制曲线是g.DrawCurve(Rp, p);
      

  5.   

    X的话用时间就可以了,Y就是mcurrent的值,mcurrent的值只要电机开启就会一直提供
    现在有个问题就是坐标的X轴是固定的,但是要一直在上面显示Y轴也就是mcurrent的值,这样来看X轴用固定的时间又是不正确的
      

  6.   

    主要的难点还是在p[i].Y,因为p[i].Y的取值与你的Y轴的刻度有关系。
      

  7.   

    错误
    错误 11 当前上下文中不存在名称“dt”
    错误 12 当前上下文中不存在名称“dt”
      

  8.   

    你可以把时间取出来放在X轴上,这样时间与mcurrent就对应起来了。。Y轴是固定的,X轴是变化的。
      

  9.   


    大哥,dt就是DataTable啊,我想弄明白点,mcurrent是一个量?你想做成实时变化的?实时变化的就放在Timer控件里头。。
      

  10.   

            private void pictureBox3_Paint(object sender, PaintEventArgs e)
            {
                int count = mcurrent++;
                Point[] p = new Point[count];
                for (int i = 0; i < count; i++) 
                {
                    p[i].X = pictureBox3.Width / count * i;
                    p[i].Y = pictureBox3.Height - Convert.ToInt32((mcurrent * pictureBox3.Height / 10));
                }
                e.Graphics.DrawLines(new Pen(Color.Yellow), p);        }
    写成这样,但是没有反应不能画出曲线
    假设其中mcurrent大概在65左右,Y轴最大刻度100,让mcurrent能实时显示到坐标系中去
      

  11.   


    首先自己写个类 ,然后把 类DrawLineS放到Timer的Timer_Tick中即可。类你参考一下下面的代码
          
        public Bitmap mybitmap;
        public void DrawLineS(Color color, float Xmax, float Ymax, PictureBox picbox, Point[] ptlist)
            {
               mybitmap = new Bitmap(picbox.Width, picbox.Height);//设定位图大小
                Graphics doublebufferg = Graphics.FromImage(mybitmap);//从位图上获取“画布”
                doublebufferg.Clear(Color.White);//用背景色刷新            Rectangle rect = new Rectangle(0, 0, picbox.Width, picbox.Height);
                doublebufferg.FillRectangle(new SolidBrush(Color.White), rect);            //要显示的实时曲线部分
                  Point temp = new Point();
                for (int j = 0; j < picbox.Width / 5 - 1; j++)
                {
                    temp = ptlist[j + 1];
                    ptlist[j] = new Point(temp.X - 5, temp.Y);
                }            Point lastpt = new Point();
                lastpt.X = picbox.Width;
                lastpt.Y = mcurrent * picbox.Height /10;
                ptlist[picbox.Width / 5 - 1] = lastpt;
                doublebufferg.DrawLines(new Pen(color, 1), ptlist);            //将缓冲中的位图绘制到我们的窗体上
                Graphics g = picbox.CreateGraphics();//创建 PictureBox窗体的画布            g.Clear(Color.White);
              g.DrawImage(mybitmap, 0, 0);
            }
      

  12.   


       public Point[] ptlist;
       private void Frm_Load(object sender, EventArgs e)
            {
                //设置控件的样式和行为,以减少图像的闪烁
                this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint, true);
                this.SetStyle(ControlStyles.ResizeRedraw, true);
                this.UpdateStyles();            //实例化数组
                ptlist = new Point[this.pictureBox1.Width / 5];
                Point pt;
                for (int i = 0; i < this.pictureBox1.Width / 5; i++)
                {
                    pt = new Point();
                    pt.X = 5 * i;//5个像素绘制一个点
                      pt.Y = mcurrent * this.pictureBox1.Height /10;                ptlist[i] = pt;
                }       
            }
      

  13.   


    private void timer1_Tick(object sender, EventArgs e)
    {
          drawtest.DrawLineS(Color.Blue, pictureBox1, ptlist);
    }
      

  14.   

    错误 13 当前上下文中不存在名称“drawtest” F:\LM3S无刷\WindowsApplication1\WindowsApplication1\Form1.cs 311 13 WindowsApplication1
      

  15.   


    额,去掉drawtest就行了。。
      

  16.   

    去掉drawtest后报错
    错误 13 当前上下文中不存在名称“DrawLineS”
    加了public void DrawLines(Pen pen, Point[] points);后drawtest.DrawLineS(Color.Blue, pictureBox1, ptlist);行报错
    错误 6 “DrawLines”方法没有任何重载采用“3”个参数
      

  17.   

    把public void DrawLineS(Color color, float Xmax, float Ymax, PictureBox picbox, Point[] ptlist)中的float Xmax, float Ymax参数去掉即可。