Skip to content
Advertisement

Chart.js – Creating multiple charts on one page

I would like to use chart.js in my joomla-component called “bestia”. To do so I imported chart.js as media-element in the manifest.xml.

I’m calling the js by doing the following:

JHtml::script(Juri::root() . 'media/com_hostinghelden/chartjs/Chart.js');

Now I would like to use a helper to shorten things up a bit. My helper should draw a graph…

JavaScript

Well, if I call this Jhtml-Graphs, the graph is rendered correctly:

JavaScript

But if I want to add a second graph to my page, the first graph is no longer shown:

JavaScript

What can I do?

Advertisement

Answer

You are redeclaring window.onload function. Thats why you will draw only one (last) chart.

JavaScript

What you can do to fix that. Im proposing to change JHtmlGraphs class as following:

JavaScript

I modified your scripts. Now your onload function will be generated one time, from finishDrawing method:

JavaScript

And somewhere at the bottom you have to call new function:

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement