1

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.

MemeDeveloper
  • 6,457
  • 2
  • 42
  • 58
AGuyCalledGerald
  • 7,882
  • 17
  • 73
  • 120

2 Answers2

0

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.

MemeDeveloper
  • 6,457
  • 2
  • 42
  • 58
  • 1
    Oh no scratch that, sorry thought you were in WinForms for some reason. Now I see "Web" in the NS. Also - Importantly... Are you SURE your number is not larger than decimal.MaxValue i.e. look here https://stackoverflow.com/a/3413791/661584 OP seems to have a number 10x larger than your number (I am no mathematician - but Jon Skeet always knows what he's talking about) – MemeDeveloper Mar 06 '19 at 17:53
  • 1
    yes I tested, it definitely is smaller than decimal.MaxValue – AGuyCalledGerald Mar 07 '19 at 10:36
0

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

See Jon Skeet's answer here :

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

MemeDeveloper
  • 6,457
  • 2
  • 42
  • 58
  • 1
    No I tested, you are right sorry (not good with scientific notation). Your number is smaller that decimal.MaxValue so... guessing the problem is actually deeper in MS code, i.e. maybe GetRequiredLabelSize is producing a number that is larger than decimal.MaxValue – MemeDeveloper Mar 06 '19 at 18:15
  • An alternative is to use a better chart component. I have had joy in the past with Google Charts (.js version) and more recently Chart.Js https://www.chartjs.org/ – MemeDeveloper Mar 06 '19 at 18:18
  • ...or maybe it's not the YValues but AxisLabel (or a value the chart produces further up) causing the issue. i.e. what is your result.Code value ? N.B. int.MaxValue is much smaller at only 2147483647. Maybe try setting pointValue to decimal.MaxValue I guess you may get same result (from further down the line). – MemeDeveloper Mar 06 '19 at 18:22
  • 1
    thanks for the info, but we cannot change the chart provider easily – AGuyCalledGerald Mar 07 '19 at 10:34
  • @AGuyCalledGerald fairplay. So if you are not passing in any values that exceed decimal.MaxValue it makes sense that the chart code is producing a value itself further down the line that itself exceeds the limit. As I say my guess it that its a UI measurement - it's got a long enough number that when it tries to calc the pixels for all the characters (think characters * pixel width) it blows up with a number that IS larger than decimal.MaxValue. – MemeDeveloper Mar 07 '19 at 14:32
  • So you could try ensuring label text, and any control you have over number formatting etc all set to give small strings hence small number of px. Basically don't assume it's directly related to your double[] and YValues. Maybe setting some format string, or label text will sovle the issue. – MemeDeveloper Mar 07 '19 at 14:34