ComponentOne WinForms Chart使用按钮实现图表的放大和缩小

作者:控件中国网   出处:控件中国网   2015-08-18 14:05:14   阅读:13

ComponentOne WinForms Chart支持多种交互功能,通过简单地调整轴线,可以为图表创建一个缩放(Zoom)的效果。例如,你可以在你的应用程序中添加两个按钮(Zoom in和Zoom out按钮)来在运行时根据按钮的点击来调整你的轴线。这里是一份演示了如何处理Button_Click事件来控制缩放(Zoom)的代码。

// Controls zooming in
private void button1_Click(object sender, System.EventArgs e)
{
double xMin = this.c1Chart1.ChartArea.AxisX.Min;
double xMax = this.c1Chart1.ChartArea.AxisX.Max;
double xChange = (xMax - xMin) * 0.05;
this.c1Chart1.ChartArea.AxisX.Min = xMin + xChange;
this.c1Chart1.ChartArea.AxisX.Max = xMax - xChange;
double yMin = this.C1Chart1.ChartArea.AxisY.Min();
double yMax = this.C1Chart1.ChartArea.AxisY.Max;
double yChange = (yMax - yMin) * 0.05;
this.c1Chart1.ChartArea.AxisY.Min = yMin + yChange;
this.c1Chart1.ChartArea.AxisY.Max = yMax - yChange;
}
// Controls zooming out
private void button2_Click(object sender, System.EventArgs e)
{
double xMin = this.c1Chart1.ChartArea.AxisX.Min;
double xMax = this.c1Chart1.ChartArea.AxisX.Max;
double xChange = (xMax - xMin) * 0.05;
this.c1Chart1.ChartArea.AxisX.Min = xMin - xChange;
this.c1Chart1.ChartArea.AxisX.Max = xMax + xChange;
double yMin = this.c1Chart1.ChartArea.AxisY.Min();
double yMax = this.c1Chart1.ChartArea.AxisY.Max;
double yChange = (yMax - yMin) * 0.05;
this.c1Chart1.ChartArea.AxisY.Min = yMin - yChange;
this.c1Chart1.ChartArea.AxisY.Max = yMax + yChange;
}

Copyright© 2006-2015 ComponentCN.com all rights reserved.重庆磐岩科技有限公司(控件中国网) 版权所有 渝ICP备12000264号 法律顾问:元炳律师事务所
客服软件
live chat