Question

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.

Was it helpful?

Solution

The chart control as such doesn't have this logic.

Check the solution of this question.

Hope this helps.

Edit: In the meanwhile, I tried the below code snippet in a sample program with your zoom code. Now the axis values are displayed without decimals.

chart1.ChartAreas[0].AxisX.LabelStyle.Format = "0";
chart1.ChartAreas[0].AxisY.LabelStyle.Format = "0";
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top