I have a problem with setting the maximum and minimum values for the y-axis of my mschart. When setting the max or min to a value, say 10.025, the value the chart sets as max is 10.024999618530273.
mainChart.ChartAreas[selectedChartArea].AxisY.Maximum = GetRoundYAxisMax(newYMax, newYRange);
mainChart.ChartAreas[selectedChartArea].AxisY.Minimum = GetRoundYAxisMin(newYMin, newYRange);
The GetRoundYAxisMax method just returns a "round" value. Code below.
private float GetRoundYAxisMax(double calculatedMax, double yAxisRange)
{
double rangeFactor = 0;
if (yAxisRange > 10)
rangeFactor = 1;
else if (yAxisRange > 1)
rangeFactor = 4;
else if (yAxisRange > 0.1)
rangeFactor = 40;
else if (yAxisRange > 0.01)
rangeFactor = 400;
else if (yAxisRange > 0.001)
rangeFactor = 4000;
else if (yAxisRange > 0.0001)
rangeFactor = 40000;
else
rangeFactor = 400000;
float returnValue = (float)(Math.Round(calculatedMax * rangeFactor, MidpointRounding.ToEven) / rangeFactor);
return returnValue;
}
The rounding code evaluates properly and returns a correctly rounded value, but when setting this value to the max or min value on the y-axis it sets a value very close to it, but not rounded.
Any ideas why this is happening?
mainChart.ChartAreas[selectedChartArea].AxisY.LabelStyle.Format = "#.###";
– Erresen