简体   繁体   English

仅在高级图表中的工具提示系列

[英]Series for tooltip only in highcharts

I need to use several series in tooltip in a highchart chart. 我需要在highchart图表的工具提示中使用几个系列。 These series should be completely invisible except tooltip. 除工具提示外,这些系列应完全不可见。 I 've tried setting visible to false. 我尝试将visible设置为false。 However in this case, legends for that series are still visible though faded. 但是,在这种情况下,该系列的图例虽然已消失但仍然可见。 If I state "ignoreHiddenSeries: true", hidden series are not there at all and I cannot use them at tooltip. 如果我声明“ ignoreHiddenSeries:true”,则隐藏的序列根本不存在,并且无法在工具提示处使用它们。 Is there a way for this type of usage? 有没有这种使用方式? Currently I am keeping those series in global javascript arrays outside the highchart's scope and using them in tooltip formatter. 目前,我将这些系列保留在highchart范围之外的全局javascript数组中,并在工具提示格式化程序中使用它们。 I prefer to keep those data in highchart as well. 我也喜欢将这些数据保存在图表中。

By the way setting showInLegend: false, visible: false also makes the series unusable in tooltip. 通过设置showInLegend:false,visible:false的方式也使该系列在工具提示中不可用。

Each invisible serie should have two params: 每个不可见的系列应具有两个参数:

visible: false,
showInLegend: false,

You need to use the tooltip formatter and use loop over each serie / each point to print values. 您需要使用工具提示格式化程序,并在每个意向/每个点上使用循环以打印值。

tooltip: {
  formatter: function() {
    var series = this.series.chart.series,
      x = this.x,
      each = Highcharts.each,
      txt = '<span style="font-size: 10px">' + this.key + '</span><br/>';

    each(series, function(serie, i) {
                each(serie.data, function(data, j){
        if(data.x === x) {
            txt += '<span style="color:' + data.color + '">\u25CF</span> ' + data.series.name + ': <b>' + data.y + '</b><br/>';
        }
      });
    });

    return txt;
  }
},

Example: http://jsfiddle.net/697e8seo/ 示例: http//jsfiddle.net/697e8seo/

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

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