Angular -chart.js legendCallback

I can’t make it work legendCallback.

I tried to do this:

options = {
    legend: {
        legendCallback: function (chart) {
            console.log(chart);
            return 'a';
        }
    }
}

OR

options = {
    legend: {

    },

    legendCallback: function (chart) {
        console.log(chart);
        return 'a';
    }
}

I also tried to switch legendand legendCallbackin the second, but still does not work and makes no mistakes.

+4
source share
2 answers

The legendCallback function is configured in the parameters launched by Chart JS, and then becomes available for your call code by calling chartInstance.generateLegend (), which will generate HTML code to add to the element on the page.

var chartInstance = new Chart(ctx, {
    type: 'line',
    data: data,
    options: {
        legendCallback: function (chart) {
            console.log(chart);
            return 'a';
        }
    }
});

// This runs the legendCallback and returns the result
var legendHtml = chartInstance.generateLegend();
+1
source

According to Chart.js docs , legendCallback- global option ie

var chartInstance = new Chart(ctx, {
    type: 'line',
    data: data,
    options: {
        legendCallback: function (chart) {
            console.log(chart);
            return 'a';
        }
    }
});
0

Source: https://habr.com/ru/post/1651733/


All Articles