Is it possible to have two pie charts with different values using chart.js? I attempted to duplicate the script for the first chart to create a second one, but it did not display correctly. Why is the second pie chart not showing up?
$(document).ready(function() {
var ctx = $("#chart-line");
var myLineChart = new Chart(ctx, {
type: 'pie',
data: {
labels: ["Spring", "Summer", "Fall", "Winter"],
datasets: [{
data: [1200, 1700, 800, 200],
backgroundColor: ["rgba(255, 0, 0, 0.5)", "rgba(100, 255, 0, 0.5)", "rgba(200, 50, 255, 0.5)", "rgba(0, 100, 255, 0.5)"]
}]
},
options: {
title: {
display: true,
text: 'Weather'
}
}
});
});
$(document).ready(function() {
var ctx = $("#chart-line");
var myLineChart = new Chart(ctx, {
type: 'pie',
data: {
labels: ["Spring", "Summer", "Fall", "Winter"],
datasets: [{
data: [1200, 1700, 800, 200],
backgroundColor: ["rgba(255, 0, 0, 0.5)", "rgba(100, 255, 0, 0.5)", "rgba(200, 50, 255, 0.5)", "rgba(0, 100, 255, 0.5)"]
}]
},
options: {
title: {
display: true,
text: 'Weather'
}
}
});
});
Here is the HTML code:
<div class="page-content page-container" id="page-content">
<div class="padding">
<div class="row">
<div class="col-md-6">
<div class="card">
<div class="card-header">Pie chart</div>
<div class="card-body" style="height: 400px">
<div class="chartjs-size-monitor" style="position: absolute; left: 0px; top: 0px; right: 0px; bottom: 0px; overflow: hidden; pointer-events: none; visibility: hidden; z-index: -1;">
<div class="chartjs-size-monitor-expand" style="position:absolute;left:0;top:0;right:0;bottom:0;overflow:hidden;pointer-events:none;visibility:hidden;z-index:-1;">
<div style="position:absolute;width:1000000px;height:1000000px;left:0;top:0"></div>
</div>
<div class="chartjs-size-monitor-shrink" style="position:absolute;left:0;top:0;right:0;bottom:0;overflow:hidden;pointer-events:none;visibility:hidden;z-index:-1;">
<div style="position:absolute;width:200%;height:200%;left:0; top:0"></div>
</div>
</div>
<canvas id="chart-line" width="399" height="400" class="chartjs-render-monitor" style="display: block; width: 400px; height: 500px;"></canvas>
</div>
</div>
</div>
`