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;
}