我正在使用http://www.chartjs.org/中的 chart.js。
我想画一个饼图,但没有显示。我设法绘制折线图,因此加载了 Javascript。
HTML格式
<!-- Chart -->
<script type="text/javascript" src="_javascripts/chart/Chart.min.js"></script>
<!-- //Chart-->
<canvas id="browsersChart" width="400" height="100"></canvas>
<script>
var ctx = document.getElementById("browsersChart");
var myChart = new Chart(ctx, {
type: 'pie',
data: {
datasets: [{
label: 'Browsers',
data: [14, 2, 2, 2, 1],
backgroundColor: [
window.chartColors.red,
window.chartColors.orange,
window.chartColors.yellow,
window.chartColors.green,
window.chartColors.blue,
],
}],
labels: [
"Chrome"
"Firefox"
""
"MSIE"
"Mobile Safari"
]
},
options: {
responsive: true
}
};
</script>
你的代码中有一些错别字。
在标签部分中,每个标签后都需要一个逗号:
labels: [
"Chrome", // These commas at the end need added.
"Firefox",
"",
"MSIE",
"Mobile Safari"
]
您还需要在图表声明的末尾添加一个)
:
options: {
responsive: true
}
}); // The rounded bracket here needs added
将来,您应该在浏览器中使用 dev 工具。Console 选项卡将告诉您有关此类错误的信息。它确切地解释了什么行有错误。
修复这些错别字后,我得到了一个饼图正如预期。
本站系公益性非盈利分享网址,本文来自用户投稿,不代表码文网立场,如若转载,请注明出处
评论列表(41条)