Highcharts:将其他信息传递给工具提示 [英] Highcharts: passing additional information to a tooltip

查看:137
本文介绍了Highcharts:将其他信息传递给工具提示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一组数据点,我将它传递给一个看起来像

的高图表。 b $ bx:1,
y:3,
nameList:[name1,name2]
},{
x:2,
y:4,
nameList:[name3,name4]
}]

I像这样建立图表:

  $(#chart)。highcharts(StockChart,{
series :[{
data:mydata
},{
data:yourdata
}]
});

现在,我希望能够从共享工具提示中访问nameList数组, m试着做如下:

  tooltip:{
formatter:function(){
var s =;
$ .each(this.points,function(i,point){
s + = point.point.nameList;
});
return s;
},
共享:true
}

在Firebug中使用 console.log(point)的点对象,我似乎无法在其中的任何位置找到nameList条目。我如何在共享系列工具提示中访问这些辅助信息?所有帮助表示感谢。

解决方案

尤里卡!

Highcharts会为一系列的数据接受几种不同类型的输入,包括



  1. 一组数值。在这种情况下,数字值将被解释为
    和y值,并且将自动计算x值,或者从0开始,
    递增1,或者从plotOptions中给出的pointStart和pointInterval自动计算。

  2. 具有两个值的数组数组。在这种情况下,第一个值是x值,
    秒是y值。如果第一个值是一个字符串,则将其作为
    点的名称应用,并且x值会按照上述规则递增。
  3. 具有named的对象数组值。在这种情况下,对象是点配置
    对象,如下所示。


然而,类型3的处理与类型1和2不同:如果数组大于turboThreshold设置,则不会呈现类型3的数组。因此,为了解决我的问题,我只需要像这样提高turboThreshold设置:

  ... 
plotOptions :{
line:{
turboThreshold:longestArray.length + 1
}
},
...

,图表正确呈现 longestArray 数据。欢呼!唯一的缺点是由于昂贵的数据检查和长序列索引,花费相当多的时间来渲染数据以获得更长的阵列。如果你们中的任何一个人知道我可以绕过这种检查或以其他方式加快处理这些数据,我会非常感激你是否让我知道如何。


I have an array of data points that I am passing to a Highcharts chart that looks like

mydata = [{
    x: 1,
    y: 3,
    nameList: ["name1", "name2"]
}, {
    x: 2,
    y: 4,
    nameList: ["name3", "name4"]
}]

I build the chart like this:

$("#chart").highcharts("StockChart", {
    series: [{
        data: mydata
    }, {
        data: yourdata
    }]
});

Now, I would like to be able to access the nameList array from the shared tooltip, which I'm trying to do as follows:

tooltip: {
    formatter: function() {
        var s = "";
        $.each(this.points, function(i, point) {
            s += point.point.nameList;
        });
        return s;
    },
    shared: true
}

but when examining the point objects in Firebug using console.log(point), I can't seem to find the nameList entry anywhere in them. How could I access this auxiliary information in a shared series tooltip? All help is appreciated.

解决方案

Eureka!

By default, Highcharts will accept several different types of input for the data of a series, including

  1. An array of numerical values. In this case, the numberical values will be interpreted and y values, and x values will be automatically calculated, either starting at 0 and incrementing by 1, or from pointStart and pointInterval given in the plotOptions.
  2. An array of arrays with two values. In this case, the first value is the x value and the second is the y value. If the first value is a string, it is applied as the name of the point, and the x value is incremented following the above rules.
  3. An array of objects with named values. In this case the objects are point configuration objects as seen below.

However, the treatment of type 3 is different from types 1 and 2: if the array is greater than the turboThreshold setting, then arrays of type 3 won't be rendered. Hence, to fix my problem, I just needed to raise the turboThreshold setting like so:

...
plotOptions: {
    line: {
        turboThreshold: longestArray.length + 1
    }
},
...

and the chart renders the longestArray data properly. Hurray! The only drawback is that there is a considerable time spent rendering the data for much longer arrays due to "expensive data checking and indexing in long series." If any of you know how I might be able to bypass this checking or otherwise be able to speed up the processing of this data, I'd be extremely thankful if you'd let me know how.

这篇关于Highcharts:将其他信息传递给工具提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆