Chartjs-ChartJS Pie Chart How default just show 2 legend datas

0👍

I find a work way, try it.

add

legend : {

                }

into option

var donutOptions     = {
                maintainAspectRatio : false,
                responsive : true,
                animation: {
                    animateScale: true,
                    animateRotate: true
                },
                tooltips: {
                    intersect: false,
                    callbacks: {
                        label: function (tooltipItem, data) {
                            ...
                        }
                    },
                },
                plugins: {
                    datalabels: {
                        ...
                        },
                    },
                },
                legend : {

                }

            };

and use this


donutChart.chart.getDatasetMeta(0).data[index].hidden = true;

donutChart.update();

enter image description here

Leave a comment