我用picturebox控件绘制实时曲线,只想把纵坐标扩大,这样曲线显示的比较清楚,一些小的变化也能很清楚的看到。 
查了一些以前的帖子,多是位图的放大,对我的好像没什么作用
主要是:1)能放大曲线(包括从文件读取的历史数据绘成的曲线)
        2)实时产生的曲线中横坐标是时间,要求能动态显示数据产生的时间,纵坐标是数据值。如:15:20:05时刻产生数据600(单位为摄氏度)
        放大就是坐标的放大,其实就是数据重画、刷新。
       但是我做的时候会出现数据和坐标轴时间的刷新问题
望各位大虾帮忙一下,能给出你们的意见和想法,有代码和资料者更好(高分相送)
不胜感激(着急用)

解决方案 »

  1.   

            private void Draw5(PaintEventArgs e)
            {
                try
                {
                    base.OnPaint(e);                Graphics graphics = e.Graphics;                float Peak = 0;//波峰移动
                    int PeakHeight = 0;//波峰高度
                    graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.None;
                    Pen pen = new Pen(color5, 1);
                    double x1 = this.Width;
                    double y1 = (double)Y_lenght5;
                    if (BaseLine_flg)
                    {
                        graphics.DrawLine(pen, 0, Y_lenght5 + Baseline5, this.Width, Y_lenght5 + Baseline5);
                    }                int xt = listPointF.Count - 1;
                    for (float x = this.Width; x > 0; )
                    {
                        PDrawF.PDrawF pd = new PDrawF.PDrawF();
                        pd = (PDrawF.PDrawF)listPointF[xt];
                        Peak = x ;
                        x -= pd.Spend;////////////////////////////////关键点就在这里可以动态的进行循环值,从而在显示上实现放大倍数的改变                    graphics.DrawLine(pen, (float)Peak, (float)pd.Y5, (float)x1, (float)y1);
                        x1 = (float)Peak;
                        y1 = (float)pd.Y5;
                        xt--;////////////////////////////////////////这一变量通过来循环实现提取数据
                    }            }
                catch
                {
                }
      

  2.   

    加个比例参数啊
    你看这个 行不行
      private   type   point   
            x   as   long   
            y   as   long   
      end   type   
        
      dim   Position(1)   as   point   
      ...   
      ...   
        
      sub   picture1_mousedown(...)   
      if   button-1   then     
            Position(0).x=x   
            Position(0).y=y   
      end   if   
      end   sub   
      sub   picture1_mouseup(...)   
      if   button-1   then     
            Position(1).x=x   
            Position(1).y=y   
      end   if   
      end   sub 
      

  3.   


    能否给些具体代码或者Demo?
      

  4.   

    什么版本的,我有VS2003/vs2005下的源代码,我自己开发的一个组件,不免费!
    有意,联系:[email protected]
      

  5.   

    是类似gis的鹰眼功能么?????如果是的话。简单。你选择你需要放大的区域。然后重新计算新的显示区域。然后重新显示在你选择的的窗口上!!!
      

  6.   

    重新计算,重绘
    双缓冲避免闪烁
    还有可以用flash控件来绘制,它可以支持放大缩小.但有一点必须明白,他的放大是不会重新请求数据来重绘的
      

  7.   


       #region 绘制大图(放大效果)
        //生成图像并返回bmp图像对象
        public Bitmap CreateBigCurve(DataSet ds, string style)
        {
            int n = ds.Tables[Tname].Rows.Count;
            if (n <= 21)
            {
                Width = 740;
            }
            else
            {
                Width = 100 + 32 * (n - 1);
            }
            firstPlaneGraph();
            YyLineBigCurve(ds);
            if (style == "全部")
            {
                drawingBigCurve(ds);
            }
            else
            {
                drawingBigOneCurve(ds, style);
            }
            return objBitmap;
        }
        //画纵轴虚线条并初始化图表标志
        public void YyLineBigCurve(DataSet ds)
        {
            int n, a;
            n = ds.Tables[Tname].Rows.Count;
            a = 32;
            Pen p = new Pen(Color.Black, 1);
            p.DashStyle = DashStyle.Dot;
            if (n >0)
            {
                for (int i = 0; i < n; i++)
                {
                    int xx = 70 + a * i;
                    if (i>0)
                    {
                        objGraphics.DrawLine(p, xx, Height - 30, xx, 30);
                    }
                    string sa = ds.Tables[Tname].Rows[i][0].ToString();
                    objGraphics.DrawString(sa.Substring(0,4), new Font("宋体", 9), new SolidBrush(Color.Black), new Point(xx - 10, Height - 27));
                    objGraphics.DrawString(sa.Substring(5,sa.Length-13), new Font("宋体", 9), new SolidBrush(Color.Black), new Point(xx - 10, Height - 15));
                }
            }
        }
        //初始化Y轴刻度数字,并绘制曲线(三条)
        public void drawingBigCurve(DataSet ds)
        {
            int n;
            float a;
            double max;
            n = ds.Tables[Tname].Rows.Count;
            a = 0;
            max = 0;
            if (n > 0)
            {
                for (int i = 0; i < n; i++)
                {
                    if (max < Convert.ToDouble(ds.Tables[Tname].Rows[i][1].ToString()))
                    {
                        max = Math.Floor(Convert.ToDouble(ds.Tables[Tname].Rows[i][1].ToString()));
                    }
                    if (max < Convert.ToDouble(ds.Tables[Tname].Rows[i][2].ToString()))
                    {
                        max = Math.Floor(Convert.ToDouble(ds.Tables[Tname].Rows[i][2].ToString()));
                    }
                    if (max < Convert.ToDouble(ds.Tables[Tname].Rows[i][3].ToString()))
                    {
                        max = Math.Floor(Convert.ToDouble(ds.Tables[Tname].Rows[i][3].ToString()));
                    }
                }
                double len = max.ToString().Length;
                double f = Convert.ToDouble(max.ToString().Substring(0, 2)) + 1;
                double Ymax = f * Math.Pow(10, (len - 2));
                //初始化Y轴刻度数字
                for (int i = 1; i < 11; i++)
                {
                    int yy = (Height - 30 - 34 * i) - 6;
                    int xx, aa;
                    aa = Convert.ToInt32((Ymax / 10) * i);
                    if (aa.ToString().Length > 1)
                    {
                        xx = 60 - 6 * (aa.ToString().Length - 1);
                    }
                    else
                    {
                        xx = 60;
                    }
                    objGraphics.DrawString(aa.ToString(), new Font("宋体", 9), new SolidBrush(Color.Black), new Point(xx, yy));
                }
                //定义点数组
                PointF[] p1 = new PointF[n];
                PointF[] p2 = new PointF[n];
                PointF[] p3 = new PointF[n];
                if (n >= 3)
                {
                    a = 32;
                    for (int i = 0; i < n; i++)
                    {
                        float x1, y1, x2, y2, x3, y3;
                        //初始化点的坐标
                        x1 = 70 + a * i;
                        y1 = Convert.ToSingle(Height - 30) - Convert.ToSingle(Math.Floor(Convert.ToDouble(ds.Tables[Tname].Rows[i][1].ToString()) / Ymax * 340));
                        x2 = 70 + a * i;
                        y2 = Convert.ToSingle(Height - 30) - Convert.ToSingle(Math.Floor(Convert.ToDouble(ds.Tables[Tname].Rows[i][2].ToString()) / Ymax * 340));
                        x3 = 70 + a * i;
                        y3 = Convert.ToSingle(Height - 30) - Convert.ToSingle(Math.Floor(Convert.ToDouble(ds.Tables[Tname].Rows[i][3].ToString()) / Ymax * 340));
                        //构造点
                        p1[i] = new PointF(x1, y1);
                        p2[i] = new PointF(x2, y2);
                        p3[i] = new PointF(x3, y3);
                    }
                }
                //绘制曲线
                if (n >= 2)
                {
                    objGraphics.DrawCurve(new Pen(Color.Red, 2), p1, Tension);
                    objGraphics.DrawCurve(new Pen(Color.Blue, 2), p2, Tension);
                    objGraphics.DrawCurve(new Pen(Color.Yellow, 2), p3, Tension);
                }
            }
        }
        //初始化Y轴刻度数字,并绘制曲线(一条)
        public void drawingBigOneCurve(DataSet ds, string style)
        {
            int n;
            float a;
            double max;
            n = ds.Tables[Tname].Rows.Count;
            a = 0;
            max = 0;
            if (n > 0)
            {
                for (int i = 0; i < n; i++)
                {
                    if (max < Convert.ToDouble(ds.Tables[Tname].Rows[i][1].ToString()))
                    {
                        max = Math.Floor(Convert.ToDouble(ds.Tables[Tname].Rows[i][1].ToString()));
                    }
                }
                double len = max.ToString().Length;
                double f = Convert.ToDouble(max.ToString().Substring(0, 2)) + 1;
                double Ymax = f * Math.Pow(10, (len - 2));
                //初始化Y轴刻度数字
                for (int i = 1; i < 11; i++)
                {
                    int yy = (Height - 30 - 34 * i) - 6;
                    int xx, aa;
                    aa = Convert.ToInt32((Ymax / 10) * i);
                    if (aa.ToString().Length > 1)
                    {
                        xx = 60 - 6 * (aa.ToString().Length - 1);
                    }
                    else
                    {
                        xx = 60;
                    }
                    objGraphics.DrawString(aa.ToString(), new Font("宋体", 9), new SolidBrush(Color.Black), new Point(xx, yy));
                }
                //定义点数组
                PointF[] p1 = new PointF[n];
                if (n >= 3)
                {
                    a = 32;
                    for (int i = 0; i < n; i++)
                    {
                        float x1, y1;
                        //初始化点的坐标
                        x1 = 70 + a * i;
                        y1 = Convert.ToSingle(Height - 30) - Convert.ToSingle(Math.Floor(Convert.ToDouble(ds.Tables[Tname].Rows[i][1].ToString()) / Ymax * 340));
                        //构造点
                        p1[i] = new PointF(x1, y1);
                    }
                }
                //绘制曲线
                if (n >= 2)
                {
                    if (style == "shuf_jie")
                    {
                        objGraphics.DrawCurve(new Pen(Color.Red, 2), p1, Tension);
                    }
                    else if (style == "guag_shl")
                    {
                        objGraphics.DrawCurve(new Pen(Color.Blue, 2), p1, Tension);
                    }
                    else
                    {
                        objGraphics.DrawCurve(new Pen(Color.Yellow, 2), p1, Tension);
                    }
                }
            }
        }
        #endregion
      

  8.   

    我的组件,是一个多图对比软件中的截图
    使用鼠标左键拉出一个选区选择后
    http://album.hi.csdn.net/App_Uploads/null1/20080921/172753328.JPG?d=20080921172904203[/img]
      

  9.   

     你的曲线是实时的吗?
    横坐标能动态显示吗?
    能否发一个Demo?
    [email protected]
    谢谢
      

  10.   

    我只是开发用,不是商业用的
    要是你愿意的话,就发给我一些相关的资料或者Demo,非常感谢。
    要是不方便的话,也就算了。
    非常感谢你的支持和帮助。谢谢
      

  11.   

    你好,能否发一个Demo?
    [email protected]
    谢谢。。
      

  12.   

    楼主,在画线之前,需要对纵坐标进行处理:
    加入一个系数,可以调整伸缩
    加入一个基值,可以调整位置简单的说就是:y'= k*y+b
      

  13.   

    下面的代码表示的是CUP的使用比率曲线,当把窗体拉伸的时候图像的比例会有变化,楼主可以参考下: public partial class Form1 : Form
    {
    public Form1()
    {
    InitializeComponent();
                this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw, true);
    }
    private PerformanceCounter _oPerformanceCounter;
    private Queue<float> queue;
    protected override void OnLoad(EventArgs e)
    {
    base.OnLoad(e);
    this._oPerformanceCounter = new PerformanceCounter("Processor", "% Processor Time", "_Total");
    this.queue = new Queue<float>();
    Timer timer = new Timer();
    timer.Interval = 200;
    timer.Tick += new EventHandler(timer_Tick);
    timer.Start();
    } void timer_Tick(object sender, EventArgs e)
    {
    float _nVal = _oPerformanceCounter.NextValue();
    this.queue.Enqueue(_nVal);
    if (this.queue.Count > 50)
    {
    this.queue.Dequeue();
    }
    this.Invalidate();
    }
    protected override void OnPaint(PaintEventArgs e)
    {
    base.OnPaint(e);
    if (this.queue.Count > 1)
    {
    float[] fa = this.queue.ToArray(); for (int i = 1; i < fa.Length; i++)
    {
    e.Graphics.DrawLine(SystemPens.ControlText, i * 5, this.ClientRectangle.Height - fa[i] * this.ClientRectangle.Height / 100, (i - 1) * 5, this.ClientRectangle.Height - fa[i - 1] * this.ClientRectangle.Height / 100);
    }
    }
    }
    protected override void OnFormClosed(FormClosedEventArgs e)
    {
    base.OnFormClosed(e);
    _oPerformanceCounter.Dispose();
    }
    }
    }
      

  14.   

    我的支持实时显示,数据是N个List<float>,只要向其加数据点,然后在需要时刷新(Init..())就可以了。其中有一个属性"每分钟数据点个数",用于确定时间坐标基数。用鼠标拉出选区后放大,再拉再放大,可以无限,双击回退到上一个放大显示的状态.
      

  15.   

    楼主可以参考一下开源的ZedGraph控件!
    http://www.codeproject.com/KB/graphics/zedgraph.aspx
      

  16.   

    可否给些代码?
    谢谢
    [email protected]
      

  17.   

     private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
            {
                try
                {
                    Cursor.Current = myCursor;
                    Graphics graphics = pictureBox1.CreateGraphics();
                    Rectangle sourceRectangle = new Rectangle(e.X - 10, e.Y - 10, 20, 20); //要放大的区域 
                    Rectangle destRectangle = new Rectangle(e.X - 20, e.Y - 20, 40, 40);//放成多大,自己看看
                    graphics.DrawImage(myImage, destRectangle, sourceRectangle, GraphicsUnit.Pixel);
                }
                catch
                { }
            }
      

  18.   

    LZ这个贴子结了么?
    遇到同样的问题啊,LZ搞定没?
    一点头绪没有,现在刚开始学习画图,LZ如有相关程序或者资料,能传我一份,不胜感激啊!!
    [email protected]