//縮放的技巧
//首先找到待縮放的區域,例如橫軸x1-x2,縱軸y1-y2
//那么待放到的區域就是x=x1;x=x2;y=y1;y=y2;這四條線組成的矩形
//首先確定矩形的左上角的坐標,然后確定矩形的寬和高
需要注意的是TeeChart縮放,依賴的是像素點,所以需要求出的左上角的坐標是,像素點的坐標;
而像素點的坐標原點在TChar的左上角
通過代碼來實現縮放
/// <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 { } }
實現后的效果