MudChart [TimeSeries]: Fix Types other than T="double" to work#12925
Merged
danielchalmers merged 2 commits intoMudBlazor:devfrom Apr 1, 2026
Merged
MudChart [TimeSeries]: Fix Types other than T="double" to work#12925danielchalmers merged 2 commits intoMudBlazor:devfrom
danielchalmers merged 2 commits intoMudBlazor:devfrom
Conversation
Contributor
|
Could you add a unit test for an integer chart? |
Contributor
Author
|
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: The PR code passes. Let me know if this is enough |
Anu6is
approved these changes
Apr 1, 2026
Member
|
Thank you! |
This was referenced Apr 8, 2026
Open
This was referenced Apr 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Currently TimeSeries fails with types like
intif it is set asT="int". At runtime it tries to convertTimeValue<int>toTimeValue<double>and just silently fails without drawing any of the points but making the skeleton of the chart. The culprit line:MudBlazor/src/MudBlazor/Components/Chart/Charts/TimeSeries.razor.cs
Line 357 in e7235a7
as it fails to convert
(TimeValue<double>)(object)data[dataPointIndex]which isTimeValue<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 TTests
Checklist: