简体   繁体   English

如何从json数据标记Highcharts工具提示?

[英]How to label Highcharts tooltip from json data?

i am passing data as JSON to highcharts this JSON comes from a java method so i cant change this...so please dont suggest to change JSON format... my code for highchart is below... 我正在将数据作为JSON传递到highcharts,此JSON来自java方法,所以我无法更改此...所以请不要建议更改JSON格式...我的highchart代码如下所示...

var json = [{
    "value": 12,
    "name": "platform1",
    "key": "event4"
}, {
    "value": 10,
    "name": "platform1",
    "key": "event1"
}, {
    "value": 14,
    "name": "platform1",
    "key": "event3"
}, {
    "value": 9,
    "name": "platform1",
    "key": "event2"
}, {
    "value": 13,
    "name": "platform3",
    "key": "event4"
}, {
    "value": 13,
    "name": "platform3",
    "key": "event1"
}];
var processed_json = new Array();
$.map(json, function (obj, i) {
    processed_json.push([obj.key, parseInt(obj.value), obj.name]);
});

$('#container').highcharts({
    chart: {
        type: 'column'
    },
    xAxis: {
        type: "category"
    },
    tooltip: {
        formatter: function () {
            return 'Branch: <b>' + this.series.name +
                '</b><br/>Platform: ' + this.point.y;
        }
    },
    series: [{
        name: 'Data',
        data: processed_json
    }]
});

i am trying to put platform name on the tooltip as i hover over...but i can not find any way to do that...plus is there any way i can create legends as number of platforms...right now i only have one legend named "Data". 我试图将平台名称悬停在工具提示上...但是我找不到任何方法...再加上有什么方法可以创建图例作为平台数量...现在我只有一个图例称为“数据”。

jfiddle can be found here : http://jsfiddle.net/QTJb7/ jfiddle可以在这里找到: http : //jsfiddle.net/QTJb7/

You need to use object instead of array, in point definition and add paramter in your $.map. 您需要在点定义中使用对象而不是数组,并在$ .map中添加参数。

$.map(json, function (obj, i) {
    processed_json.push({name: obj.key,y: parseInt(obj.value),customName : obj.name });
});

tooltip: 提示:

tooltip: {
    formatter: function () {
        return 'Branch: <b>' + this.series.name +
            '</b><br/>Platform: ' + this.point.name + ' <br> name ' + this.point.customName;
    }
},

http://jsfiddle.net/QTJb7/1/ http://jsfiddle.net/QTJb7/1/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM