Skip to content

MudChart [TimeSeries]: Fix Types other than T="double" to work#12925

Merged
danielchalmers merged 2 commits intoMudBlazor:devfrom
pkaaz:fix/timeseries-chart-type-fix
Apr 1, 2026
Merged

MudChart [TimeSeries]: Fix Types other than T="double" to work#12925
danielchalmers merged 2 commits intoMudBlazor:devfrom
pkaaz:fix/timeseries-chart-type-fix

Conversation

@pkaaz
Copy link
Copy Markdown
Contributor

@pkaaz pkaaz commented Mar 31, 2026

Currently TimeSeries fails with types like int if it is set as T="int". At runtime it tries to convert TimeValue<int> to TimeValue<double> and just silently fails without drawing any of the points but making the skeleton of the chart. The culprit line:

return (TReturn)(object)data[dataPointIndex];

as it fails to convert (TimeValue<double>)(object)data[dataPointIndex] which is TimeValue<int>

(TReturn)(object)data[dataPointIndex] | '(TReturn)(object)data[dataPointIndex]' threw an exception of type 'System.InvalidCastException' | MudBlazor.Charts.TimeValue {System.InvalidCastException}

Example snippet
https://try.mudblazor.com/snippet/wkGKuRxPRsOzFKij

The fix changes double variables to generic T so it matches the Types. It also adds an IFormattable constraint to TNumber for TimeValue so .ToString() could be used for the TooltipLabelFormat and is already a requirement on T

Tests

  • Tested on MudBlazor.Docs.Server - changing all the types to int and comparing the results to match
  • Packaging the project and using where I needed it and it shows the correct result without resorting to conversions
  • Running the current UnitTests - All passing, at least locally

Checklist:


  • I've added or updated relevant unit tests
  • I looked at the unit tests for other charts and they have no tests for Types except for DonutChart. I can try and add some if needed though.

@mudbot mudbot bot added the bug Unexpected behavior or functionality not working as intended label Mar 31, 2026
@pkaaz pkaaz changed the title TimeSeries: Fix Types other than T="double" to work MudChart [TimeSeries]: Fix Types other than T="double" to work Mar 31, 2026
@ScarletKuro ScarletKuro requested a review from Anu6is March 31, 2026 13:20
@Anu6is
Copy link
Copy Markdown
Contributor

Anu6is commented Mar 31, 2026

Could you add a unit test for an integer chart?

@mudbot mudbot bot added the needs: tests A maintainer has explicitly asked for test cases to be added label Apr 1, 2026
@pkaaz
Copy link
Copy Markdown
Contributor Author

pkaaz commented Apr 1, 2026

I added a test for Integer that is basically Identical to the BasicExample one just with integer types as the data would remain the same. The old code throws this during this test:

Message: 
System.InvalidCastException : Unable to cast object of type 'MudBlazor.Charts.TimeValue`1[System.Int32]' to type 'MudBlazor.Charts.TimeValue`1[System.Double]'.

The PR code passes. Let me know if this is enough

@danielchalmers danielchalmers merged commit 90bb200 into MudBlazor:dev Apr 1, 2026
11 checks passed
@danielchalmers
Copy link
Copy Markdown
Member

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Unexpected behavior or functionality not working as intended needs: tests A maintainer has explicitly asked for test cases to be added

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants