highcharts - 将回调函数传递给 typescript 中 highchart 图例中的 labelFormatter

标签 highcharts typescript angular callback highcharts-ng

我正在尝试使用 typescript 在 Angular2 中使用 HighCharts。

我正在尝试格式化我的图例文本,并在其旁边显示图像。 HighChart 图例具有 labelFormatter 属性来提供回调函数。

http://api.highcharts.com/highcharts#legend.labelFormatter

Callback function to format each of the series' labels. The this keyword refers to the series object, or the point object in case of pie charts. By default the series or point name is printed.

但我不知道如何将 typescript 中的回调函数传递给 labelFormatter 属性。

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);
}

但是我的 seriesDetails 对象未定义。

如果我在任何地方使用 this 关键字,它会引用该组件而不是系列信息。

最佳答案

根据documentation :

Callback function to format each of the series' labels. The this keyword refers to the series object, or the point object in case of pie charts. By default the series or point name is printed.

我猜你在粗箭头函数中弄错了“this”。恕我直言,最简单的方法只需遵循文档语法( jsfiddle ):

labelFormatter: function () {
    return this.name + ' (click to hide)';
}

关于highcharts - 将回调函数传递给 typescript 中 highchart 图例中的 labelFormatter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38605381/

相关文章:

javascript - Angular Uncaught( promise ): ChunkLoadError: Loading chunk XXXfailed

javascript - Highcharts 工具提示中的附加数据

highcharts - 最小/最大 yAxis 在 Highcharts 中无法正常工作

javascript - Highcharts - 仅将样式应用于某些标签

javascript - 通过增加 javascript 中的数字使记录唯一

css - 更改大纲输入字段中的背景颜色

javascript - 折线图系列向下钻取到另一个折线图系列

javascript - javascript for 循环内的异步调用

typescript - Angular 2 : Application freezing when model is changed from select input

Angular - 取消以前的搜索请求并仅保留最后一个