Chart.js with Datacore

What I’m trying to do

Hi guys, I’m playing around with datacore and was wandering if it is possible to render chartjs with datacorejs or datacorejsx like it is with dataviewjs.

I tried to return window.renderChart(data, container), but that doesn’t work.

Any ideas? I appreciate every help.

1 Like

This might be a longshot, but window.renderChart() is not a part of dataview, but rather a part of the Charts plugin. As such, it should be usable by also datacorejs as is when that plugin is installed and enabled.

Not sure, but I don’t think, the syntax should change a lot. You might need a slightly different reference to the container where it should be placed, but the call itself is just a pure javascript call.

The function is window.renderChart() is available, but datacore doesn’t provide access its container, “this” returns the global object and I don’t think the container can be access through it.

techy-robot on github provided me with a solution.
You can use this.__P in the standard preact component. See an example below.

return function View() {
	const data = {
	    type: 'doughnut',
	    data: {
	        labels: ['a', 'b'],
	        datasets: [{
	            data: [10, 20]
	        }]
	    }
	}
	window.renderChart(data, this.__P)
	return;
}
1 Like