Highchart工具提示PointOptionsObject接口实现

问题描述 投票:0回答:1

除x,y和z外,我为Highchart传递了额外的字段(例如color,data_status,data_oos,data_soc和data_status_cd)。

x: timestamp,
y: soc,
z: duration,
color: color,
data_status: state,
data_oos: oosFg,
data_soc: soc,
data_status_cd: errorCode

我的意图是在Highchart工具提示格式化程序功能中使用这些自定义值。我在https://api.highcharts.com/class-reference/Highcharts.PointOptionsObject中找不到用于打字稿的Highchart PointOptionsObject的清晰实现示例。有没有办法访问这些值?以下是我尝试使用的格式化程序功能的一部分。

tooltip: {
          //useHTML: true,
          formatter: function() {
            var point = this.point,
            series = this.series,
            pointIndex = point.index,
            oos = point.options.data_oos,
            status = point.options.data_status,
            soc = point.options.data_soc,
            status_code = point.options.data_status_cd;

            const text = "<strong>Charging: " + status_code + " " + "| Out of Service</strong>";
            return text;
}
angular typescript highcharts tooltip
1个回答
0
投票

我能够通过实现自己的自定义接口来实现此目的,该接口由PointOptionsObject继承。

    interface Custom extends Highcharts.PointOptionsObject {
            data_state: number;
            data_oos: boolean;
            data_soc: number;
            data_status_cd: number;
            z: number;
            timeZone: string;
}

然后,我创建了Custom的对象并将其设置为Point数据的options标志,可以从如下工具顶部再次访问该标志。

        tooltip: {
                //useHTML: true,
                formatter: function() {
                    var custom = this.point.options as Custom; 
                    var [state, oos, statusCode, soc, text] = ["Not Connected", "", "", "", ""];
                statusCode = (custom.data_status_cd !== null) ? (": " + custom.data_status_cd + " ") : "";
...

    }
© www.soinside.com 2019 - 2024. All rights reserved.