highcharts将多个值传递给工具提示

dev*_*ter 23 javascript tooltip highcharts

我需要在工具提示上显示3个值:时间,值和另一个值(更改).

我看到了这个例子(但是jsdfiddle没有用).

我试过这个

//each loop..
indice.push(["time", "value1", "value2"]);
Run Code Online (Sandbox Code Playgroud)

,工具提示设置

tooltip:
    {
    useHTML: true,
    formatter: function()
    {
      return '' + Highcharts.dateFormat('%H:%M:%S', this.x) +'; '+ this.y + this.z(<-is this right?);
    }
},
Run Code Online (Sandbox Code Playgroud)

和系列

series:
[{
    type: 'area',
    data: indice
}]
Run Code Online (Sandbox Code Playgroud)

可以帮忙吗?thsnks.

Lin*_*ger 44

如果要为x和y值以外的点传递其他数据,则必须为该值命名.在以下示例中,我将以下三个附加值添加到每个数据点:

{
  y: 3,
  locked: 1,
  unlocked: 1,
  potential: 1,
}
Run Code Online (Sandbox Code Playgroud)

然后,要在工具提示中访问并显示这些值,请使用以下命令:

tooltip: 
{
     formatter: function() { return ' ' +
        'Locked: ' + this.point.locked + '<br />' +
        'Unlocked: ' + this.point.unlocked + '<br />' +
        'Potential: ' + this.point.potential;
     }
}
Run Code Online (Sandbox Code Playgroud)


MyG*_*GaN 7

如果您在多系列Highstocks图表中想要在工具提示中显示系列特定数据,您可以执行类似的操作.

var series = [];

// Populate our series
series.push({
  name: "small_cities",
  displayName: "Small Cities",
  color: "#123456",
  data: [...]
});
series.push({
  name: "Countries",
  displayName: "Countries",
  color: "#987654",
  data: [...]
});

chart: {
  ...

  tooltip: {
    formatter: function() {
      var s = '';
      $.each(this.points, function(i, point) {
        s += '<br /><span style="color:' + this.series.color + '">' +
             point.series.userOptions.displayName + '</span>: ' + point.y;
      });
      return s;
    }
  },

  ...
}
Run Code Online (Sandbox Code Playgroud)

现在你会看到很好的系列名称"Small Cities"而不是series.name(small_cities).您可以在中找到您在系列中设置的所有属性this.points[].series.userOptions.有关更多格式化程序选项,请查看Highstocks文档.


dev*_*ter 5

我想通了,我在数据数组中传递了3个值

indice.push([(new Date(value.x)).getTime(), val_change[0], val_change[1]]);
Run Code Online (Sandbox Code Playgroud)

series:[{type:'area',name:titleindice,data:indice,showInLegend:false //禁用show/hide icon}]

并在工具提示中

tooltip:
                {
                    useHTML: true,
                    formatter: function()
                    {
                        var color = "";

                        return Highcharts.dateFormat('%H:%M:%S', this.x) + this.y +  this.point.config[2] ;

                    }
                },
Run Code Online (Sandbox Code Playgroud)


poo*_*per 5

两种方式.

1

series: [
          { ...
            tooltip:
              {pointFormat: "<span style=\"color:{series.color}\">{series.name}</span>: <b>{point.y} {y2}</b><br/>"}
          }, ...          
         ]
o = Highcharts.Point.prototype.tooltipFormatter
Highcharts.Point.prototype.tooltipFormatter=function(format){return o.call(this, format).replace("{y2}", this.config[2]);}
Run Code Online (Sandbox Code Playgroud)

2

 a = new Highcharts.StockChart(options); 
 a.series[0].tooltipFormatter = function(item) { return "<span style=\"color:{" + item.series.color+"\">" +item.series.name+"</span>: <b>"+item.y+item.point.config[2]+"</b><br/>"; }
Run Code Online (Sandbox Code Playgroud)