首页 文章

饼图图例 - Chart.js

提问于
浏览
14

我需要帮助将饼图的编号放在图例中

Chart Image

如果我用鼠标悬停图表我可以看到相对于每个项目的数字

我想在传奇中显示它

到目前为止重要的代码:

var tempData = {
    labels: Status,
    datasets: [
        {
            label: "Status",
            data: Qtd,
            backgroundColor: randColor
        },

    ]
};

var ctx = $("#pieStatus").get(0).getContext("2d");
var chartInstance = new Chart(ctx, {
    type: 'pie',
    data: tempData,
    options: {
         title: {
            display: true,
            fontsize: 14,
            text: 'Total de Pedidos por Situação'
        },
        legend: {
            display: true,
            position: 'bottom',

        },
        responsive: false
    }

});

“Qtd”,“randColor”已经是值“var”

1 回答

  • 27

    您需要在选项中编辑 generateLabels 属性:

    options: {
        legend: {
            labels: {
                generateLabels: function(chart) {
                     // Here
                }
            }
        }
    }
    

    因为在你自己创建一个很棒的模板是相当混乱的 . 我建议使用与the source code中相同的功能,然后编辑所需的内容 .

    这是一个small jsFiddle,你可以看到它是如何工作的(编辑的行 - 来自38 - 被评论),结果如下:

    enter image description here

相关问题