I have a winforms application which contains a chart control called
comparisonChart
I have implemented Zoom capability in the chart control by subscribing to the mousewheel event and doing the following.
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);
}
}
When I zoom in on the chart, the X axis values show decimal values.
To remove the decimal values I have also done the following.
comparisonChart.Series[0].XValueType = ChartValueType.Int32;
But again it is showing decimal values when I zoom in.