2012-12-19 11 views
15

Ho una tabella di grafici ad alta risoluzione con due serie di dati che utilizzano valori denominati. Nei miei suggerimenti per una serie, voglio fare riferimento a un punto dati della serie. Quindi la soluzione in questa risposta: How to use a different formatter on Highcharts in each curve of the same graphic? non mi aiuta. Ho bisogno di più di una semplice ToolTipText, ho bisogno di un formattatore:Posso usare due diversi formattatori per le descrizioni comandi di grafici elevati?

Per uno:

formatter: function() { 
    return this.x + ': ' + this.series.name + 
    '<br> $' + Highcharts.numberFormat(this.y, 0); 
    } 

E per l'altro:

formatter: function() { 
    return 'In ' + this.x + ' the median value was' + this.median + 
    'and the total $' + Highcharts.numberFormat(this.y, 0);       
} 

risposta

28

All'interno formattatore this Refer alla serie mirata, è possibile aggiungere un if/else all'interno del formattatore e restituire una stringa per ognuno, come il seguente.

tooltip: { 
    shared: false, 
    formatter: function() { 
     var text = ''; 
     if(this.series.name == 'MSFT') { 
      text = this.x + ': ' + this.series.name + 
        '<br> $' + Highcharts.numberFormat(this.y, 0); 
     } else { 
      text = 'In ' + this.x + ' the median value was' + this.median + 
        'and the total $' + Highcharts.numberFormat(this.y, 0); 
     } 
     return text; 
    } 
} 

demo

+7

+1, grazie - anche se a mio parere , è meglio usare 'this.series.options.id' invece di' this.series.name' in modo che non si basi su qualcosa che potrebbe facilmente cambiare. L'ID può essere impostato durante l'inizializzazione della serie. –

-1

Ecco un esempio. L'esempio violino è here:

tooltip: { 
      formatter: function() { 
       var s = '<b>' + Highcharts.dateFormat('%A, %b %e, %Y', this.x) + '</b>'; 

       $.each(this.points, function() { 
        s += '<br/>1 USD = ' + this.y + ' EUR'; 
       }); 

       return s; 
      } 
     }, 
3

si può facilmente definire un formattatore toolip per ogni serie - vedere qui: http://api.highcharts.com/highcharts/plotOptions.series.tooltip

{ 
    tooltip: { 
      shared: true 
    }, 
    series: { 
    name: 'some series name', 
    data: mydata, 
    tooltip: { 
     valueSuffix: ' bar' 
    } 
    } 
} 

Esempio: http://jsfiddle.net/28qzg5gq/

+0

Questo non è un formattatore, sono solo suffissi. L'aggiunta di un formattatore nell'oggetto di configurazione di una sola serie deve essere eseguita tramite la funzione 'pointFormatter' - [example] (http://jsfiddle.net/28qzg5gq/12/). –

Problemi correlati