.net chart crashes with large decimal as point value

435 views Asked by At

I have some problems with a .net chart series. I add points to the series like this

point = new DataPoint();
point.AxisLabel = result.Code;
point.YValues = new double[] { pointValue };

For the value 4.0343262175104857E+28, chart.SaveImage() crashes.

Value was either too large or too small for a Decimal.

at System.Decimal..ctor(Double value) at System.Web.UI.DataVisualization.Charting.Axis.GetRequiredLabelSize(ChartGraphics chartGraph, Single maxLabelSize, Single& resultSize) at System.Web.UI.DataVisualization.Charting.Axis.Resize(ChartGraphics chartGraph, ElementPosition chartAreaPosition, RectangleF plotArea, Single axesNumber, Boolean autoPlotPosition) at System.Web.UI.DataVisualization.Charting.ChartArea.Resize(ChartGraphics chartGraph) at System.Web.UI.DataVisualization.Charting.ChartPicture.Resize(ChartGraphics chartGraph, Boolean calcAreaPositionOnly) at System.Web.UI.DataVisualization.Charting.ChartPicture.Paint(Graphics graph, Boolean paintTopLevelElementOnly) at System.Web.UI.DataVisualization.Charting.ChartImage.GetImage(Single resolution) at System.Web.UI.DataVisualization.Charting.Chart.SaveImage(Stream imageStream)

The value is smaller than decimal.MaxValue though. It works if I use int.MaxValue.

2

There are 2 answers

2
MemeDeveloper On

My guess (and it is a guess) is that the issue is probably the same/very similar as here

It looks like maybe it's a bug you are getting "bubbling up" from something else in the Chart (i.e. not the setting of the YValues directly, but somewhere closer to the UI.

I am guessing this based on the linked post (similar issue), and the fact that your exception stack shows UI level calls e.g.

System.Web.UI.DataVisualization.Charting.Axis.GetRequiredLabelSize

My only suggestion without a sample project / more to go on: try to strip down the chart's functionality (disable features etc) until the issue goes away.

Alternatively if the chart is too embedded already and that would be a pain: make a new chart with the most simple usage, and see if it gives the same exception.

Sorry can't help more.

6
MemeDeveloper On

I think your number may actually be larger than decimal.MaxValue

See Jon Skeet's answer here :

https://stackoverflow.com/a/3413791/661584