6

在以下示例中,我如何格式化两个系列和标志的工具提示?

http://jsfiddle.net/gh/get/jquery/1.7.1/highslide-software/highcharts.com/tree/master/samples/stock/plotoptions/flags/

我想在系列工具提示中显示额外信息,并在标志工具提示中显示其他数据。

4

3 回答 3

11

使用以下功能作为工具提示格式化程序 -

tooltip: {
  shared:true,
formatter: function(){
        var p = '';
        console.log(this);

        if(this.point) {
          p += '<b>'+ Highcharts.dateFormat('%A, %b %e, %Y', this.point.x) +'</b><br/>';
          p += this.point.config.text // This will add the text on the flags
        }
        else {              
          p += '<b>'+ Highcharts.dateFormat('%A, %b %e, %Y', this.x) +'</b><br/>';
          $.each(this.points, function(i, series){
            p += '<span style="color:' + this.series.color + '">' + this.series.name + '</span>: <b>'+ this.y + ' kWh ($' + Highcharts.numberFormat(this.y * rate, 0) + ')</b><br/>';
          });

        }
        return p;
      }}

另请参阅此 JSFiddle:http: //jsfiddle.net/aTcFe/

于 2012-07-26T13:01:48.187 回答
8

一种方法是创建一个工具提示格式化程序来检查当前对象是否是一个点。

tooltip: {
            formatter: function(){
                if(this.point) {
                    return "this is a flag"
                }
                else {
                    return "this is a line"
                }
            }                
        }

您可以更进一步并为您的标志命名,然后检查该点是否有名称(而不是它是否存在)以防止非标志点获得相同的格式。

这是您修改的示例以反映以前的http://jsfiddle.net/aTcFe/

于 2012-05-11T01:21:22.827 回答
1

使用 Highstock 2.1.7,您总是会得到一个this.point对象,因此您应该使用它this.series.type === 'flags'来检测标志是否存在。

一个例子是:

formatter: function () {
     if (this.series.type === 'flags') {
          // Flags formatting
     }
     else {
          // Default formatting
     }
}
于 2015-08-18T15:48:52.793 回答