How do I trigger a function in my Component from an onclick event in my chart.js?
export class ReportesComponent implements OnInit {
constructor(public _router: Router, private data: ReporteService) {}
this.chart = new Chart('myChart', {
type: 'bar',
data: {
labels: this.barCharLabels,
datasets: [
{
data: this.dataCharCartera,
label: 'Cartera',
backgroundColor: 'rgb(232,95,95)'
},
{
data: this.dataChar,
label: 'Penetracion',
backgroundColor: 'rgb(95,145,232)'
}
]
},
options: {
legend : {
display: true
},
responsive: true,
scales: {
xAxes: [{
ticks: {
beginAtZero: true
}
}]
},
onClick: (e) => {
var element = this.getElementAtEvent(e);
if (element.length) {
console.log(element[0]._view.label)
}
console.log(element);
this.Showtest(e);
}
}
});
Showtest(e): void {
console.log(e)
this._router.navigate(['/Menu/Informacion']);//
}
}
I am looking to call the Showtest function and retrieve the element value within the onClick function of my chart.js. Thank you.