我有一个 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;
但是当我放大时它再次显示十进制值。