Handling Null or empty value returns for chart dataset

I am using charts for a user dashboard and I receive the following error if the invoke 'get' for the dataset returns no results:

dotnet: warn: Microsoft.AspNetCore.Components.Server.Circuits.RemoteRenderer[100]
      Unhandled exception rendering component: Value was either too large or too small for a Decimal.
      System.OverflowException: Value was either too large or too small for a Decimal.
         at System.Number.ThrowOverflowException(TypeCode type)
         at System.Decimal.DecCalc.VarDecFromR8(Double input, DecCalc& result)
         at System.Decimal.op_Explicit(Double value)
         at Radzen.Blazor.Rendering.CategoryAxis.OnParametersSet()
         at Microsoft.AspNetCore.Components.ComponentBase.CallOnParametersSetAsync()
         at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync()
         at Radzen.Blazor.RadzenChartComponentBase.SetParametersAsync(ParameterView parameters)

How does one handle chart datasets that have the potential to be empty? The dataset is an IEnumberable pulled from an SQL View. I have no issues as long as the dataset returns at least one item

So I did discover that if the minimum value axis is set to 'null' or blank this solves the problem (empty 'get' invoke actions display no data with a starting point "0' to a max of '1'), but then it sets the minimum value for items that do produce a value to the smallest returned value, effectively hiding that item or items from the chart. I see no way to add a condition through Radzen IDE to allow me to check for null on minimum value. I would like everything to display min value of zero, even when the value is null

1 Like

We shall need a reproduction of this problem. I can't get this exception by using an empty IEnumerable as the Data of a chart.

@korchev, what is the best way for me to give you a reproduction without sending my full dataset with the views?

Hi All,

A bit late to the party with this one, but I just had the same issue and was able to resolve it via code as below:

First, set the Min value to be bound to a variable that you have defined:

<RadzenValueAxis Min=@chartMinValue>

Then in code-behind, set the minimum value based on the contents of the dataset you are attaching to the chart:

// Declaration of nullable variable (important)
private int? chartMinValue = 0;

// In your GetData Method
chartMinValue = _timeRecords.Count() > 0 ? 0 : null;

Obviously you will need to amend the code to suit you use case, but hopefully this will help someone else at some point!

1 Like