TeeChart缩放


//缩放的技巧
//首先找到待缩放的区域,例如横轴x1-x2,纵轴y1-y2
//那么待放到的区域就是x=x1;x=x2;y=y1;y=y2;这四条线组成的矩形
//首先确定矩形的左上角的坐标,然后确定矩形的宽和高

需要注意的是TeeChart缩放,依赖的是像素点,所以需要求出的左上角的坐标是,像素点的坐标;

而像素点的坐标原点在TChar的左上角

TeeChart缩放_第1张图片

通过代码来实现缩放

 /// <summary>
        /// 缩放
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button6_Click(object sender, EventArgs e)
        {
            //缩放的技巧
            //首先找到待缩放的区域,例如横轴10-30,纵轴4-8
            //那么待放到的区域就是x=10;x=30;y=4;y=8;这四条线组成的矩形
            //首先确定矩形的左上角的坐标,然后确定矩形的宽和高
            try
            {
                if (tChart1 != null)
                {
                    if (tChart1.Series.Count > 0)
                    {
                        int x1 = Convert.ToInt32(textBox8.Text);//x轴的起始
                        int x2 = Convert.ToInt32(textBox9.Text);//x轴的结束
                        int y1 = Convert.ToInt32(textBox11.Text);
                        int y2 = Convert.ToInt32(textBox10.Text);
                        int x; int y; int height; int width; Rectangle r;
                        Series series = tChart1.Series[0];

                        //单独横向
                        //xmin = series.CalcXPosValue(x1);
                        //xmax = series.CalcXPosValue(x2);
                        //ymin = series.CalcYPosValue(tChart1.Axes.Left.MinYValue);
                        //ymax = series.CalcYPosValue(tChart1.Axes.Left.MaxYValue);
                        //x = xmin;
                        //y = ymax;
                        //height = ymin - ymax;
                        //width = xmax - xmin;
                        //Console.WriteLine("x:{0},y:{1}", x, y);
                        //Console.WriteLine("width:{0},height:{1}", width, height);
                        //r = new Rectangle(x, y, width, height);//a和b代表的是矩形左上角的点的坐标
                        //tChart1.Zoom.ZoomRect(r);

                        //单独纵向
                        //ymin = series.CalcYPosValue(y1);
                        //ymax = series.CalcYPosValue(y2);
                        //xmin = series.CalcXPosValue(tChart1.Axes.Bottom.MinXValue);
                        //xmax = series.CalcXPosValue(tChart1.Axes.Bottom.MaxXValue);
                        //x = xmin;
                        //y = ymax;
                        //height = ymin - ymax;
                        //width = xmax - xmin;
                        //Console.WriteLine("x:{0},y:{1}", x, y);
                        //Console.WriteLine("width:{0},height:{1}", width, height);
                        //r = new Rectangle(x, y, width, height);
                        //tChart1.Zoom.ZoomRect(r);

                        x = series.CalcXPosValue(x1);
                        y = series.CalcYPosValue(y2);
                        width = series.CalcXPosValue(x2)-series.CalcXPosValue(x1);
                        height = series.CalcYPosValue(y1)-series.CalcYPosValue(y2);
                        r = new Rectangle(x, y, width, height);
                        tChart1.Zoom.ZoomRect(r);
                    }
                }
            }catch
            {
            }
        }

实现后的效果

TeeChart缩放_第2张图片

你可能感兴趣的:(chart)