Highcharts工具提示中的附加数据

时间:2018-01-30 03:00:19

标签: javascript highcharts

我在大多数情况下都使用了以下Highchart,但我无法在堆叠条形图中的第3个系列的工具提示中显示自定义数据点。我是否在工具提示中为我的自定义数据格式化了系列中的数据错误? USMFalse和sentNotAnswered是我感兴趣的自定义数据项.USMFalse和sentNotAnswered是一起添加的值,为我提供相应的数据值。即第一个在3 + 8 = 11,这是堆积条的红色成分

这里的小提琴示例JSFiddle

...
series: [{
       "type": "bar",
       "data": [3056, 6681, 4169, 4399, 2046, 6504, 8435],
       "color": "#D4D3D2",
       "name": "Non-Targeted"
     },

     {
       "type": "bar",
       "data": [4, 0, 1, 0, 6, 0, 0],
       "color": "#16DE47",
       "name": "Participating"
     },

     {
       "type": "bar",
       "color": "#FF5733",
       "name": "Targeted",
       "data": [11, 0, 0, 0, 13, 0, 0],
       "USMFalse": [3, 0, 0, 0, 4, 0, 0],
       "sentNotAnswered": [8, 0, 0, 0, 9, 0, 0]
     }

   ]

1 个答案:

答案 0 :(得分:2)

您必须将Targeted数组定义为对象数组,而不是使用数值数组:

{
   "type": "bar",
   "color": "#FF5733",
   "name": "Targeted",
   "data": [{
     y: 11,
     USMFalse: 3,
     sentNotAnswered: 8
   }, {
     y: 0,
     USMFalse: 0,
     sentNotAnswered: 0
   }, {
     y: 0,
     USMFalse: 0,
     sentNotAnswered: 0
   }, {
     y: 0,
     USMFalse: 0,
     sentNotAnswered: 0
   }, {
     y: 13,
     USMFalse: 4,
     sentNotAnswered: 9
   }, {
     y: 0,
     USMFalse: 0,
     sentNotAnswered: 0
   }, {
     y: 0,
     USMFalse: 0,
     sentNotAnswered: 0
   }]
 }

然后,在格式化程序功能中,您需要参考当前点:

if (this.series.name == 'Targeted') {
  text = '<b>' + this.x + '</b> <br>' 
    + this.series.name + ': ' + this.y + '<br>' 
    + this.point.USMFalse + '<br>' 
    + this.point.sentNotAnswered;
}

这是一个小伙伴:https://jsfiddle.net/d15wad74/