如何通过添加缩放按钮在Windows窗体图表中控制放大和缩小

时间:2016-11-16 05:24:02

标签: c# winforms charts mschart

如何通过添加ZoomIn和ZoomOut按钮

来控制Windows窗体图中的放大和缩小
chart1.ChartAreas["draw"].AxisY.ScaleView.ZoomReset();

1 个答案:

答案 0 :(得分:3)

放大按钮:

Axis ax = chart1.ChartAreas[0].AxisX;
ax.ScaleView.Size = double.IsNaN(ax.ScaleView.Size)?   
                    (ax.Maximum - ax.Minimum) / 2 : ax.ScaleView.Size /= 2;

缩小:

Axis ax = chart1.ChartAreas[0].AxisX;
ax.ScaleView.Size = double.IsNaN(ax.ScaleView.Size)?   
                    ax.Maximum : ax.ScaleView.Size *= 2;
if (ax.ScaleView.Size > ax.Maximum - ax.Minimum)
{
    ax.ScaleView.Size = ax.Maximum;
    ax.ScaleView.Position = 0;
}