Highcharts - 使用功能更改工具提示

时间:2014-02-04 10:13:25

标签: javascript php highcharts

所以我使用Highcharts(特定的li3_highcharts助手)来显示通话时间。我可以使用一个函数在工具提示中显示“{point.y}”,但为了使其更具可读性,我需要能够将“{point.y}”传递给我的secondsToTime()函数,该函数显示秒数作为可读时间00:00:00。

以秒为单位打印正确的时间:

'tooltip' => ['pointFormat' => '(function(){return "{point.y}";})()']

但是当我尝试在secondsToTime()函数中传递“{point.y}”时,我只得到'NaN',因为它不是数字。我还在函数中添加了一个parseInt(),并将其作为字符串传递,但没有。

'tooltip' => ['pointFormat' => '(function(){return secondsToTime("{point.y}");})()']

以后哪些地方可以通过此功能,以便它能够正常工作?或者一些解决方法?

提前致谢。

2 个答案:

答案 0 :(得分:0)

我并非100%确定这是问题所在,但看起来您将引用的字符串传递给函数而不是整数值。尝试:

'tooltip' => ['pointFormat' => '(function(){return secondsToTime({point.y});})()']

对不起。再看一遍,我想我知道问题是什么。

你正在使用' pointFormat',它应该是一个字符串,而不是一个函数。

http://api.highcharts.com/highcharts#tooltip.pointFormat

如果你想调用一个函数,有一个'格式化程序'选项

http://api.highcharts.com/highcharts#tooltip.formatter

我认为你需要这样的东西:

'tooltip' => ['formatter' => 'function(){return secondsToTime(point.y);}']

答案 1 :(得分:0)

SteveP是正确的我认为除了你需要

'tooltip' => ['formatter' => 'function(){return secondsToTime(this.y);}']

而不是

'tooltip' => ['formatter' => '(function(){return secondsToTime(this.y);})()']