5

I'm currently working on a port for chart.js to blazor. There we do interop from JavaScript to C# and the other way around. Chart.js supports callbacks like the custom tick callback or the onClick, onHover and onLeave legend handlers. In order to have these callbacks call into C#, we setup a function with ...args that calls a C# method through blazor. Blazor then takes the result from the C# method and returns it to JavaScript. That way we have full communication between the two.

When we need to worry about the return value (like with the custom tick callbacks), we need to ensure that chart.js gets the correct values. In (server-side) blazor, you can only communicate with JavaScript asynchronously because it's built on websockets. That means that the return value of such an interop call is always a Promise object and chart.js doesn't understand that.

Now I'd like to know what I can do instead. Is there a way for chart.js to work with async callbacks?

Ps. I'm not experienced with Javascript. I have already asked another question about synchronously waiting for promises (in the same context) but that doesn't work.

Pps. There is some more information (but mostly on the C# side) in this dedicated github issue.

Joelius
  • 3,839
  • 1
  • 16
  • 36
  • Perhaps a clue here https://stackoverflow.com/questions/28921127/how-to-wait-for-a-javascript-promise-to-resolve-before-resuming-function this mean you will need to create a small JS wrapper for each callback. – Remi THOMAS Mar 30 '21 at 06:31

0 Answers0