0

我有一个 winforms 应用程序,其中包含一个名为

comparisonChart

我通过订阅鼠标滚轮事件并执行以下操作在图表控件中实现了缩放功能。

private void comparisonChartMouseWheel(object sender, MouseEventArgs e)
    {
        if (e.Delta < 0)
        {
            this.comparisonChart.ChartAreas[0].AxisX.ScaleView.ZoomReset(0);
            this.comparisonChart.ChartAreas[0].AxisY.ScaleView.ZoomReset(0);
        }
        else if (e.Delta > 0)
        {
            double xMin = this.comparisonChart.ChartAreas[0].AxisX.ScaleView.ViewMinimum;
            double xMax = this.comparisonChart.ChartAreas[0].AxisX.ScaleView.ViewMaximum;
            double yMin = this.comparisonChart.ChartAreas[0].AxisY.ScaleView.ViewMinimum;
            double yMax = this.comparisonChart.ChartAreas[0].AxisY.ScaleView.ViewMaximum;
            double posXStart = this.comparisonChart.ChartAreas[0].AxisX.PixelPositionToValue(e.Location.X) - (xMax - xMin) / 4;
            double posXFinish = this.comparisonChart.ChartAreas[0].AxisX.PixelPositionToValue(e.Location.X) + (xMax - xMin) / 4;
            double posYStart = this.comparisonChart.ChartAreas[0].AxisY.PixelPositionToValue(e.Location.Y) - (yMax - yMin) / 4;
            double posYFinish = this.comparisonChart.ChartAreas[0].AxisY.PixelPositionToValue(e.Location.Y) + (yMax - yMin) / 4;
            this.comparisonChart.ChartAreas[0].AxisX.ScaleView.Zoom(posXStart, posXFinish);
            this.comparisonChart.ChartAreas[0].AxisY.ScaleView.Zoom(posXStart, posXFinish);
        }

    }

当我放大图表时,X 轴值显示十进制值。

要删除十进制值,我还执行了以下操作。

comparisonChart.Series[0].XValueType = ChartValueType.Int32;

但是当我放大时它再次显示十进制值。

4

1 回答 1

2

图表控件本身没有这个逻辑。

检查这个问题的解决方案。

希望这可以帮助。

编辑:与此同时,我在示例程序中使用您的缩放代码尝试了以下代码片段。现在轴值显示为不带小数。

chart1.ChartAreas[0].AxisX.LabelStyle.Format = "0";
chart1.ChartAreas[0].AxisY.LabelStyle.Format = "0";
于 2014-01-29T05:42:48.537 回答