-1

我喜欢highcharts的工具提示功能!然而到目前为止,我只能显示从系列到工具提示的数据,而不能显示系列外的数据。我正在考虑添加更多系列,但这些添加的系列最终会出现在图表中,这不是我想要的。谁能帮我?谢谢!

4

2 回答 2

2

我使用的方法是为每个系列数据点添加一个附加属性:

series:[{
    name:"Example Series",
    data:[{x:1,y:2,tt:"Tooltip for point 1"},{x:2,y:3,tt:"Tooltip for point 2"}]
}]

这些附加属性可用于工具提示格式化程序上下文

tooltip: {
    formatter: function() {
        if(typeof this.point.tt != 'undefined'){
            return this.point.tt;
        }else{
            return ''+this.x +' / '+ this.y +'';
        }                    
    }
},

如果您使用两个元素数组来传递数据,则必须转换为具有 x 和 y 属性的对象。

于 2013-03-26T14:08:59.767 回答
0

您可以在工具提示格式化程序中访问您喜欢的任何数据,包括外部变量(如果它们在范围内)。

jsFiddle 示例

var extraVariable = "This is not part of the chart"

var chart = new Highcharts.Chart({
    tooltip: {
        formatter: function() {
            return 'The value for <b>'+ this.x +
                '</b> is <b>'+ this.y +'</b>  I\'m also showing this: '+extraVariable;
        }
    },
于 2013-03-21T21:29:23.057 回答