Removing legend on charts with chart.js v2

前端 未结 3 1813
天命终不由人
天命终不由人 2021-01-30 10:10

I\'m making a homepage using, Bootstrap, JQuery and Chart.js (v2). I had my implementation working using v1, but recently just got into Bower and downloaded v2 using that.

相关标签:
3条回答
  • 2021-01-30 10:18

    You simply need to add that line legend: { display: false }

    0 讨论(0)
  • 2021-01-30 10:33

    The options object can be added to the chart when the new Chart object is created.

    var chart1 = new Chart(canvas, {
        type: "pie",
        data: data,
        options: {
             legend: {
                display: false
             },
             tooltips: {
                enabled: false
             }
        }
    });
    
    0 讨论(0)
  • 2021-01-30 10:43

    You can change default options by using Chart.defaults.global in your javascript file. So you want to change legend and tooltip options.

    Remove legend

    Chart.defaults.global.legend.display = false;
    

    Remove Tooltip

    Chart.defaults.global.tooltips.enabled = false;
    

    Here is a working fiddler.

    0 讨论(0)
提交回复
热议问题