简体   繁体   English

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

[英]How do I pass in parameters to the Highcharts pointFormatter callback function

Highcharts has a pointFormatter option that accepts a callback function. Highcharts具有一个可以接受回调函数的pointFormatter选项。 I want to use a couple variables in that formatter. 我想在该格式化程序中使用几个变量。 How do I do that? 我怎么做? Sorry if this is obvious; 抱歉,这很明显; I'm new to JS. 我是JS的新手。 This is what I have so far: 这是我到目前为止的内容:

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

Obviously priceArr and buysPoints1 aren't defined in the scope...how do I fix that? 显然,priceArr和buysPoints1没有在范围内定义...我该如何解决?

If they're in the scope of chart.addSeries then they should be in scope for the pointFormatter callback function. 如果它们在chart.addSeries的范围内,则它们应该在pointFormatter回调函数的范围内。

From the pointformatter examples it looks like highcharts does not pass any parameters to the callback. pointformatter示例来看,highcharts似乎没有将任何参数传递给回调。

What you are doing is adding unnecessary parameters to the pointformatter callback function and overwriting your previous values for priceArr and buysPoints1 with undefined . 您正在做的是向pointformatter回调函数添加不必要的参数,并使用undefined覆盖之前的priceArrbuysPoints1值。 They are undefined because when highcharts calls the pointformatter callback for you, it does not pass any values into the call, so your parameters (priceArr and buysPoints1) are undefined inside the function. 它们是undefined因为当highcharts为您调用pointformatter回调时,它不会将任何值传递到调用中,因此您的参数(priceArr和buysPoints1)在函数内部未定义。

Try removing them from the callback parameters. 尝试从回调参数中删除它们。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM