I am currently experimenting with integrating HighCharts into an Angular2 project using TypeScript.
My goal is to customize the appearance of the legend text, adding an image next to it. I've found that HighCharts provides a labelFormatter property within the legend section for this purpose.
http://api.highcharts.com/highcharts#legend.labelFormatter
The labelFormatter function allows you to modify the format of each series' labels. When used, 'this' refers to either the series object or, in the case of pie charts, the point object. By default, the series or point name is displayed.
However, I'm struggling to figure out how to pass a callback function from TypeScript to the labelFormatter property.
updateChart(): void {
let newOptions = {
legend: {
useHTML: true,
itemMarginBottom: 10,
enabled: true,
floating: true,
align: 'center',
verticalAlign: 'top',
labelFormatter: (s) => this.getLegendLabel(s),
y: 35
}
}
}
getLegendLabel(seriesDetails) {
console.log(seriesDetails);
}
When executing this code, I am encountering an issue where the seriesDetails object is returning as undefined.
Additionally, whenever I use the this keyword, it references the component itself rather than the series information.