将其他数据设置为highcharts系列 [英] Set Additional Data to highcharts series
问题描述
有什么方法可以将一些额外的数据传递给系列对象,这些数据将用于在图表中显示'tooltip'?
例如$ b
tooltip:{
formatter:function(){
return'< b>'+ this.series.name + '< / b>< br />'+
Highcharts.dateFormat('%b%e',this.x)+':'+ this.y;
}
这里我们只能使用series.name,this.x&这个系列。可以说我需要通过另一个动态值单独与数据集并可以通过系列对象访问。这可能吗?
谢谢大家。
是的,如果你设置如下的系列对象,其中每个数据点是一个散列,然后您可以传递额外的值:
new Highcharts .Chart({
...,
系列:[{
name:'Foo',
data:[
{
y:3,
myData:'firstPoint'
},
{
y:7,
myData:'secondPoint'
},
{
y :1,
myData:'thirdPoint'
}
]
}]
});
在您的工具提示中,您可以通过传入的对象的point属性访问它:
工具提示:{
formatter:function(){
return'Extra data:< b>'+ this.point.myData +'< / b>';
$ b $ p
$ b 完整示例:
is there any way to pass some additional data to the series object that will use to show in the chart 'tooltip'?
for example
tooltip: {
formatter: function() {
return '<b>'+ this.series.name +'</b><br/>'+
Highcharts.dateFormat('%b %e', this.x) +': '+ this.y;
}
here we can only use series.name , this.x & this.y to the series. lets say i need to pass another dynamic value alone with the data set and can access via series object. is this possible?
Thank you all in advance.
解决方案 Yes, if you set up the series object like the following, where each data point is a hash, then you can pass extra values:
new Highcharts.Chart( {
...,
series: [ {
name: 'Foo',
data: [
{
y : 3,
myData : 'firstPoint'
},
{
y : 7,
myData : 'secondPoint'
},
{
y : 1,
myData : 'thirdPoint'
}
]
} ]
} );
In your tooltip you can access it via the "point" attribute of the object passed in:
tooltip: {
formatter: function() {
return 'Extra data: <b>' + this.point.myData + '</b>';
}
}
Full example here: http://jsfiddle.net/japanick/dWDE6/314/
这篇关于将其他数据设置为highcharts系列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!