简体   繁体   English

angular-chart.js legendCallback

[英]angular-chart.js legendCallback

I can't seem to make the legendCallback work. 我似乎无法使legendCallback工作。

I tried putting it like 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 switching legend and legendCallback in the second one but still doesn't work nor give any error. 我也尝试在第二个中切换legendlegendCallback ,但仍然不起作用,也没有任何错误。

The legendCallback function is setup on the options, run by Chart JS and then made available to your calling code via a call to chartInstance.generateLegend() which will generate the HTML for you to append to an element on the page. legendCallback函数在选项上设置,由Chart JS运行,然后通过调用chartInstance.generateLegend()使您的调用代码可用,它将生成HTML以供您附加到页面上的元素。

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();

According to Chart.js docs , legendCallback is a global option ie 根据Chart.js文档legendCallback是一个全局选项即

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM