highcharts pass multiple values to tooltip

后端 未结 5 1824
清歌不尽
清歌不尽 2020-12-08 20:58

I need to display 3 values on the tooltip: the time, the value and another value(change).

I saw this example (but the jsdfiddle is not working).

I tried thi

相关标签:
5条回答
  • 2020-12-08 21:37

    What i have tried is concatenating series name with x-axis and y-axis value and it works fine for me. What issue you are facing?

    tooltip: { formatter: function () { return this.x + ': ' + this.series.name + ': ' + this.y; } }
    
    0 讨论(0)
  • 2020-12-08 21:44

    I figured it out, I pass 3 values in the data array

    indice.push([(new Date(value.x)).getTime(), val_change[0], val_change[1]]);
    

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

    and in the tooltip

    tooltip:
                    {
                        useHTML: true,
                        formatter: function()
                        {
                            var color = "";
    
                            return Highcharts.dateFormat('%H:%M:%S', this.x) + this.y +  this.point.config[2] ;
    
                        }
                    },
    
    0 讨论(0)
  • 2020-12-08 21:47

    two ways.

    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]);}
    

    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/>"; }
    
    0 讨论(0)
  • 2020-12-08 21:48

    If you, in a multi series Highstocks chart, want to display series specific data in the tooltip you could do something like this.

    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;
        }
      },
    
      ...
    }
    

    Now you'll see nice series names "Small Cities" instead of the series.name (small_cities). All attributes you set on the series can be found in this.points[].series.userOptions. For more formatter options take a look at the Highstocks docs.

    0 讨论(0)
  • 2020-12-08 22:00

    If you want to pass additional data for a point other than the x and y values, then you have to name that value. In the following example I add the following three additional values to each data point:

    {
      y: 3,
      locked: 1,
      unlocked: 1,
      potential: 1,
    }
    

    Then to access and display those values in the tooltip I use the following:

    tooltip: 
    {
         formatter: function() { return ' ' +
            'Locked: ' + this.point.locked + '<br />' +
            'Unlocked: ' + this.point.unlocked + '<br />' +
            'Potential: ' + this.point.potential;
         }
    }
    
    0 讨论(0)
提交回复
热议问题