javascript - 在 highcharts tooltip.pointFormat 中使用点值进行数学运算时出现问题

标签 javascript highcharts

我正在用 highcharts 创建一个图表。我试图在将鼠标悬停在散点图中的点上时显示自定义字符串。这个字符串需要我从那个点开始稍微操纵数据,但我无法做到这一点。

我知道可以通过以下方式访问数据 '{point.y}' 但这不允许我操作数据(除法、Math.floor、...)。我假设为了做到这一点,我需要将我操作数据的部分与“+”连接起来。然而,我没有尝试像 {point.y} 那样获取数据。 我试过 'this.y', 'this.point.y' 我不太确定什么有效

...
tooltip: {
    pointFormat: '{point.y} ' + this.y
},
...

我应该通过 this.y 获得通过 {point.y} 获得的内容,这样我就可以操作数据。所以

Expected: 14.345354 14.345354
Actual: 14.345354 undefined

最佳答案

您可以使用 pointFormatter 来指定返回所需值的函数。使用 pointFormat,您只能提供一个字符串,变量括在大括号中。

使用 pointFormatter ( API ) 您可以对结果进行专门的编程。例如 ( JSFiddle ):

tooltip: {
    pointFormatter: function() {
        return 'x: <b>'+this.x+'</b><br/>y: <b>'+this.y+'</b><br/>'
    }
}

类似于默认点格式。或者降低 X 和 Y 值:

tooltip: {
    pointFormatter: function() {
        return 'x: <b>'+Math.floor(this.x)+'</b><br/>y: <b>'+Math.floor(this.y)+'</b><br/>'
    }
}

关于javascript - 在 highcharts tooltip.pointFormat 中使用点值进行数学运算时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57211009/

相关文章:

javascript - 如何防止 iFrame 操作导致外部页面滚动到它

javascript - 使用第一个复选框启用广播列表

javascript - Highchart生成数组系列

javascript - Highcharts .update 修改原始数据数组

JavaScript:获取对象的第一个也是唯一的属性名称

javascript - 哪些 JavaScript 库具有以下控件

javascript - Highcharts zIndex 十字准线问题

charts - Highcharts 删除 x 轴上的空间

javascript - 我可以同步两个不同年份(闰年)的 highcharts 系列吗

javascript - 无法加载资源: the server responded with a status 404(not found)