我正在使用chart.js饼图来显示一些数据,并且我想在单击饼图时打开一个对话框。到目前为止,我已经成功地在切片点击警报中获取了所需的数据,但感到困惑关于如何在对话框中获取此数据。
'onClick': function(e) {
var activePoints = this.getElementsAtEvent(e);
var firstPoint = activePoints[0];
console.log(firstPoint)
var label = this.data.labels[firstPoint._index];
var list = this.data.list;
if (firstPoint!= undefined) {
for (let i = 0; i< list.length; i++) {
if (label === list[i].label) {
console.log(list[i].value);
alert(label + ":" + list[i].value);
<chart type="pie" [data]="data" [options]="options"></chart>
var chart = new CanvasJS.Chart("container",
{
.
.
data: [{
click: function(e){
alert( e.dataSeries.type+ ", dataPoint { x:" + e.dataPoint.x + ", y: "+ e.dataPoint.y + " }" );
},
},
]
.
.
});
chart.render();