hi i was trying to use chartjs can be found in this link www.chartjs.org
i tried to draw two chart in the same page using the samples code
i created two different div with two different ids
like this
<div id="chart1"></div>
<div id="chart2"></div>
then after including this line :
i created the first chart this way:
window.onload = function(){
var ctx1 = document.getElementById("chart1").getContext("2d");
window.myLine = new Chart(ctx1).Line(lineChartData, {
responsive: true
});
}
and the second chart this way :
window.onload = function(){
var ctx2 = document.getElementById("chart2").getContext("2d");
window.myPie = new Chart(ctx2).Pie(pieData);
};
data used for both chart is the same like as samples , so nothing changed but if i draw just one chart by itself it works great if i put the two chart at the same time i get only the pie chart
can you tell me where is the problem please i think it is some sort of conflict , but i can't find it
You could rather user jQuery to get the canvas object
now make sure the code below is not throwing js error at all
as you know, if any error in js occurs the js-runtime halts all the latter lines of code
I have not worked on different type of charts but I worked on an example and created two bar chart in a page using this code:
and in script part I do like this:
I try this code ... this solve your problem
Use only 1 window.onload
Ref: http://www.htmlgoodies.com/beyond/javascript/article.php/3724571/Using-Multiple-JavaScript-Onload-Functions.htm
First off, you only need one window.onload event. No reason to have two separate instances of that.
Second, the data sets for Pie chart and Line chart are actually very different.
Pie chart sample data:
Line chart sample data:
The line chart is likely not initializing because you are feeding it the wrong kind of data.
Use only one window.onload