Chart图:使用chart.js绘制饼图

关于Chart图的问题,在drawings of pie中经常遇到, 我正在使用http://www.chartjs.org/中的 chart.js。

我正在使用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>
1

你的代码中有一些错别字。

在标签部分中,每个标签后都需要一个逗号:

labels: [
    "Chrome", // These commas at the end need added.
    "Firefox",
    "",
    "MSIE",
    "Mobile Safari"
]

您还需要在图表声明的末尾添加一个)

    options: {
        responsive: true
    }
}); // The rounded bracket here needs added

将来,您应该在浏览器中使用 dev 工具。Console 选项卡将告诉您有关此类错误的信息。它确切地解释了什么行有错误。

修复这些错别字后,我得到了一个饼图正如预期。

本站系公益性非盈利分享网址,本文来自用户投稿,不代表码文网立场,如若转载,请注明出处

(714)
Cma分几个等级:R中的百分比等级 (含)(percentile rank formula)
上一篇
C++中指针:C++ 中指针的类型转换和类型转换
下一篇

相关推荐

发表评论

登录 后才能评论

评论列表(41条)