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
To create multiple chart, you need to create chart container tag <div id="container"></div> for each chart. Based on the requirement, you can create multiple chart containers with different id and display charts in web page.
It allows us to create responsive bar charts, pie charts, line plots, donut charts, scatter plots, and other graphs. Simply select where on your page you want a graph to appear, what type of graph you want to plot, and then provide data, labels, and other options to Chart js.
Other than that the most obvious distinction between the two is that Chart. js is canvas based, while d3. js is mainly about SVG.
Use only one window.onload
window.onload = function () { window.myRadar = new Chart(document.getElementById("canvas1").getContext("2d")).Radar(radarChartData, { responsive: true }); var G2 = document.getElementById("canvas2").getContext("2d"); window.myBar = new Chart(G2).Bar(barChartData, { responsive: true }); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With