我试图使两个图表与Chartjs出现在同一页面上,但是遇到一些错误。输出中仅显示一个图表。我使用了两个容器,每个容器中都有一个不同的id画布。请看下面的代码, 请帮忙。
<script>
Chart.defaults.global.defaultFontColor = '#470804';
let mychart = document.getElementById('mychart').getContext('2d');
x = [20,12.5,15,10,5,20,17.5];
l = ["Infrastructure","Transport","Advertisement","Taxes","R & D","Salary","Interest"];
let massPopChart = new Chart(mychart,{
type:'pie',
data:{
labels:l,
datasets:[{
data:x,
backgroundColor:[
'violet',
'indigo',
'blue',
'green',
'yellow',
'orange',
'red'
]
}]
}
});
</script>
<script>
Chart.defaults.global.defaultFontColor = '#470804';
let mychart2 = document.getElementById('mychart2').getContext('2d');
x = [20,12.5,15,10,5,20,17.5];
l = ["Infrastructure","Transport","Advertisement","Taxes","R & D","Salary","Interest"];
let massPopChart = new Chart(mychart2,{
type:'pie',
data:{
labels:l,
datasets:[{
data:x,
backgroundColor:[
'violet',
'indigo',
'blue',
'green',
'yellow',
'orange',
'red'
]
}]
}
});
</script>