Click events on Pie Charts in Chart.js

后端 未结 10 2071
失恋的感觉
失恋的感觉 2020-11-28 03:29

I\'ve got a question regard Chart.js.

I\'ve drawn multiple piecharts using the documentation provided. I was wondering if on click of a certain slice of one of the

10条回答
  •  春和景丽
    2020-11-28 03:51

    If you are using TypeScript, the code is a little funky because there is no type inference, but this works to get the index of the data that has been supplied to the chart: // events public chartClicked(e:any):void { //console.log(e);

        try {
            console.log('DS ' + e.active['0']._datasetIndex);
            console.log('ID ' +  e.active['0']._index);
            console.log('Label: ' + this.doughnutChartLabels[e.active['0']._index]);
            console.log('Value: ' + this.doughnutChartData[e.active['0']._index]);
    
    
        } catch (error) {
            console.log("Error In LoadTopGraph", error);
        }
    
        try {
            console.log(e[0].active);
        } catch (error) {
            //console.log("Error In LoadTopGraph", error);
        }
    
    
    
    }
    

提交回复
热议问题