Megabit / Blazorise

Blazorise is a component library built on top of Blazor with support for CSS frameworks like Bootstrap, Tailwind, Bulma, AntDesign, and Material.
https://blazorise.com/
Other
3.29k stars 531 forks source link

Numeric Format value in Charts Tooltip #324

Closed fantonifra closed 4 years ago

fantonifra commented 5 years ago

Numeric value in tooltip have a lot of decimal places. Is there some way to format the value?

image

stsrki commented 5 years ago

According to the documentation it can only be done by settings the label callback on options https://www.chartjs.org/docs/latest/configuration/tooltip.html#label-callback

The problem is that we currently don't support callbacks from JavaScript . @andrewwilkin has started some work on #313 to make callbacks between JavaScript and Blazor that can be used to format the values. I don't how much work he's done.

andrewwilkin commented 5 years ago

@fantonifra the easiest way of doing that would be to round the data before sending it to the chart if you can live with that.

There is no way of wiring up the callbacks into Blazor due to the way the interop returns a promise. I have spent a fair bit of time trying various approaches and not got anywhere.

My current thinking is to extend the object that is passed in, as ChartJS does not complain about properties in the object it does not use from my testing and use that to define what JavaScript callback options should be wired in.

Note also that as @stsrki has mentioned, with the current serializer not able to ignore null properties the JSON options are preferable if you plan to leverage ChartJS features.

stsrki commented 4 years ago

Closing for now as there is currently no easy way to handle this. @andrewwilkin workaround is the best solution for now.