由於某種原因,我無法弄清楚如何讓多個chart.js圖表加載到同一頁面上。我可以得到一個加載得很好,但是當我添加更多時,他們都沒有加載。任何想法,我做錯了什麼?試圖讓多個chart.js圖表加載在同一頁面
<div class="game-cards col-lg-5">
<div class="chart-container">
<canvas id="myChart" width="500" height="500"></canvas>
</div>
<div class="right-info">
<h4>Iowa State vs Iowa</h4>
<h5 id="time-channel">11:00 AM - Channel Goes here</h5>
<div class="total-points-live">
<h5>Total Points Bet</h5>
<h5 id="point-total">20,000</h5>
<p class="bet-button">Click To Place Bet</p>
</div>
</div>
<div>
<input class="bet-input" type="text" name="betAmount" placeholder="Wager Amount">
</div>
</div>
<div class="game-cards col-lg-5">
<div class="chart-container">
<canvas id="myChart" width="500" height="500"></canvas>
</div>
<div class="right-info">
<h4>Iowa State vs Iowa</h4>
<h5 id="time-channel">11:00 AM - Channel Goes here</h5>
<div class="total-points-live">
<h5>Total Points Bet</h5>
<h5 id="point-total">20,000</h5>
<p class="bet-button">Click To Place Bet</p>
</div>
</div>
<div>
<input class="bet-input" type="text" name="betAmount" placeholder="Wager Amount">
</div>
</div>
這是JavaScript
window.onload = function() {
var ctx = document.getElementById("myChart").getContext('2d');
var myChart = new Chart(ctx, {
type: 'doughnut',
data: {
labels: ["Iowa", "Iowa State"],
datasets: [{
backgroundColor: [
"#CC0000",
"#F1BE48",
],
data: [2000, 9000]
}]
},
options: {
responsive: true
, maintainAspectRatio: false
}
});
}
是的,謝謝!出於某種原因,我的大腦昨晚不工作,謝謝你的簡單答案。 – Branduo
不用擔心,樂意幫忙:) – Deano