javascript - 如何将参数传递给 Highcharts pointFormatter 回调函数

标签 javascript highcharts

Highcharts 有一个接受回调函数的 pointFormatter 选项。我想在该格式化程序中使用几个变量。我怎么做?抱歉,如果这是显而易见的;我是 JS 新手。这是我到目前为止所拥有的:

chart.addSeries({
      id: "buy1",
      name: "Buys for SD #1",
      type: "scatter",
      color: "#23DA47",
      data: buySellCleaner(buysPoints1),
      tooltip: { 
         pointFormatter: function(priceArr, buysPoints1) {
             return "Time" + "<b>" + unixToEST(this.x) + "</b>" + "<br/>Price: <b>" + priceArr[buySellCleaner(buysPoints1)[this.series.data.indexOf( this.point )][2]][1] + "</b>";
        }
   },
});

显然,priceArr 和 buysPoints1 未在范围内定义...我该如何解决这个问题?

最佳答案

如果它们在 chart.addSeries 的范围内那么它们应该在 pointFormatter 回调函数的范围内。

来自pointformatter examples看起来 highcharts 没有向回调传递任何参数。

您正在做的是将不必要的参数添加到 pointformatter回调函数并覆盖 priceArr 之前的值和buysPoints1undefined 。他们是undefined因为当 highcharts 为您调用 pointformatter 回调时,它不会将任何值传递到调用中,因此您的参数(priceArr 和 buysPoints1)在函数内未定义。

尝试从回调参数中删除它们。

pointFormatter: function() {
    return "Time" + "<b>" + unixToEST(this.x) + "</b>" + "<br/>Price: <b>" + priceArr[buySellCleaner(buysPoints1)[this.series.data.indexOf( this.point )][2]][1] + "</b>";
}

关于javascript - 如何将参数传递给 Highcharts pointFormatter 回调函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51030228/

相关文章:

javascript - 有没有办法禁用 Highcharts 中的标题和副标题?

基于Referrer的Javascript重定向

javascript - Highstock 为动态添加的系列添加积分

javascript - jQuery 自定义确认框允许/阻止咳嗽事件

javascript - 使用 highcharts 悬停系列时增加不同的标记大小

html - 在 HTML 表格中显示的 Highcharts

javascript - Highcharts Legend事件点击获取数据

javascript - 媒体源 api 源缓冲区追加不起作用

javascript - 带有 jQ​​uery Mobile 的三个输入的一个标签

javascript - Highcharts 饼图 : How to ignore disabled legend items