I am using Chart Js in angular. I need some events to show highlighted segment. On clicking or mousemove any segment its working fine. Now i want to highlight a legend when i click on any one but its not working. Its not event going inside click event. Can someone suggest what i am doing wrong.
.cmp
export class AppComponent implements OnInit {
chart: any;
colorOptions = ['red', 'pink']
ngOnInit() {
this.chart = new Chart('canvas', {
type: 'doughnut',
data: {
labels: ['red','pink'],
datasets: [
{
data: [55,45],
backgroundColor: ['rgba(255, 0, 0, 1)','rgba(255, 0, 0, 0.1)'],
fill: false,
},
]
},
options: {
legend: {
display: true,
labels:{
usePointStyle:true,
},
onClick: (event, legendItem) => {
console.log("This is not working")
// i want to highlight clicked legend here
}
},
tooltips:{
enabled:false
},
// events: ['click','mousemove'],
onClick: (evt, item) => {
if(item[0]) {
this.chart.update()
item[0]._model.outerRadius += 10
} else {
this.chart.update()
}
},
onHover: (evt, item) => {
if(item[0]) {
this.chart.update()
item[0]._model.outerRadius += 10
} else {
this.chart.update()
}
}
}
});
}
}
html
<div [hidden]="!chart">
<canvas id="canvas"></canvas>
</div>
Demo link
https://stackblitz.com/edit/chartjs-doughnut-chart-u1yj6h?file=src/app/app.component.html