I’d like to display a chart with some data in a admin-dashboard widget. But I’m stuck with the loading of my js libs.
Due to the fact, that the widget content is done via renderWidgetContent() the libs included with event.include( assetId = "js-chart" ); are not instantiated.
Is there some example available how to get a chart rendered in the widgets?
The renderWidgetContent() handler is not designed to be called directly. It’s called from a widget container, via renderWidgetContainer().
This container takes an ajax argument. If ajax is false, the chart scripts will be included in your page as you render the chart in the widget content. But if using ajax, you’ll need to have the scripts embedded in the page at the time you render the container. This is handled by adding a ajaxIncludes() method to your widget handler, which will return void but do an event.include( “chartjs” ) plus any CSS you might want.