Anders Nygaard
Anders Nygaard

Reputation: 5552

With HighCharts, how can I have the same tooltip formatter as my y axis

With HighCharts, is there a way for my tooltip formatter to use the selected y axis formatter? In this jsfiddle, I've added a y axis formatter (divide by thousand), but the tooltip contents remain unformatted.

Edit: I have a dynamic number of y-axis and series.

.highcharts({
    tooltip: {
      borderWidth: 1,
      borderColor: '#AAA',
      formatter: function(e){
         // do some magic here
      }
    },
    yAxis: [
        {
      id: 'score',
        min: 0,
        max: 10000,
        title: 'Score',
        labels: {
            formatter: function(e){
            return e.value/1000 + 'k';
          }
        }
      }
    ],
    series: [{
        type: 'spline',
        name: 'Laurel',
        data: [1000,2000,3000,8000,5000],
        yAxis: 'score'
    },
    {
        type: 'spline',
        name: 'Yanni',
        data: [3000,7000,3000,2000,1000],
        yAxis: 'score'
    }]
});

Upvotes: 2

Views: 1312

Answers (1)

Core972
Core972

Reputation: 4114

You must set the tooltip formatter Api like that :

tooltip:{
  ...
  formatter: function(){
    var text = '';
    if(this.series.index == 0) {
        text = this.series.name + ' : ' + this.y/1000 + 'k';
    } else {
        text = '<b>' + this.series.name + '</b> : ' + this.y ;
    }
    return text;
  }
}

Fiddle

Edit for multiple yAxis

Upvotes: 1

Related Questions