Chart.js:如何在图例中使用onClick选项时从包含多个图表的页面访问图表?

问题描述 投票:0回答:1

我在一个页面中有多个图表,我想向图表添加自定义onClick操作。下面的代码来自chart.js文档。它显示了只有一个图表时如何添加操作https://www.chartjs.org/docs/latest/configuration/legend.html#custom-on-click-actions

[在存在多个图表时,如何访问用户单击以更新单个图表的图表?

onClick: function(e, legendItem) {
    var index = legendItem.datasetIndex;
    var ci = this.chart;
    var meta = ci.getDatasetMeta(index);

    // See controller.isDatasetVisible comment
    meta.hidden = meta.hidden === null ? !ci.data.datasets[index].hidden : null;

    // We hid a dataset ... rerender the chart
    ci.update();
}
angular chart.js chart.js2 ng2-charts
1个回答
0
投票

没关系。

'this.chart'使我们可以访问当前图表,即使我们在同一页面上有多个图表也是如此

© www.soinside.com 2019 - 2024. All rights reserved.