mercredi 24 avril 2019

Highcharts tooltip formatter function does not display values in table correct

I have created an if else statement in my highcharts tooltip formatter function in order to display y values from different point.series.name. Values from first and second series in the array displays correct, but styling for the last series.name values (HINDCAST - SPREAD) does not display correct, because font-size and point.series.color does not show. I suppose the problem is the table tags? Please see fiddle

https://jsfiddle.net/marialaustsen/w4k87jyo/

tooltip: {
        shared: true,
        useHTML: true,
        formatter: function() {
          var aYearFromNow = new Date(this.x);
          aYearFromNow.setFullYear(aYearFromNow.getFullYear() + 5);
          var tooltip = '<table><span style="font-size: 16px">' +
            Highcharts.dateFormat('%e/%b/%Y', new Date(this.x)) + '-' + Highcharts.dateFormat('%e/%b/%Y', aYearFromNow) + '</span><br/><tbody>';
          //loop each point in this.points
          $.each(this.points, function(i, point) {
            if (point.series.name === 'Observations') {

              tooltip += '<tr><th style="font-size: 14px; color: ' + point.series.color + '">' + point.series.name + ': </th>' +
                '<td style="font-size: 14px">' + point.y + '℃' + '</td></tr>'


            } else if (point.series.name === 'BOXPLOT') {



              const x = this.x;
              const currentData = this.series.data.find(data => data.x === x);
              const boxplotValues = currentData ? currentData.options : {};
              tooltip += `<span style="font-size: 14px; color: #aaeeee"> 
                            Max: ${boxplotValues.high.toFixed(2)}<br>
                      Q3: ${boxplotValues.q3.toFixed(2)}<br>
                      Median: ${boxplotValues.median.toFixed(2)}<br>
                      Q1: ${boxplotValues.q1.toFixed(2)}<br>
                      Low: ${boxplotValues.low.toFixed(2)}<br></span>`;

            } else {

              tooltip += '<tr><th style="font-size: 14px; color: ' + point.series.color + '">' + point.series.name + ': </th>' +
                '<td style="font-size: 14px">' + point.point.low + '℃ -' + point.point.high + '℃' + '</td></tr>' +
                '</tbody></table>';

            }
          });
          return tooltip;
        }
      },


Aucun commentaire:

Enregistrer un commentaire