customize highcharts tooltip to show datetime

SkyNet_citizen picture SkyNet_citizen · Jun 11, 2013 · Viewed 58.8k times · Source

I'm developing a project that is expected to show this graph: http://jsfiddle.net/Kc23N/

When I click a point (tooltip) I want to show a date understandable, not the value in milliseconds.

I think needs to change this piece of code:

tooltip: {
      headerFormat: '<b>{series.name}</b><br>',
      pointFormat: '{point.x} date, {point.y} Kg',                        
}

how do I do? any kind help is appreciated.

Thanks

Answer

rscnt picture rscnt · Jun 11, 2013

You can use moment.js to get the values formatted, but Highcharts has it's own date formatting functionality which would be more idiomatic with Highcharts. It can be attached onto the tooltip option in the highcharts constructor like so:

        tooltip: {
            formatter: function() {
                return  '<b>' + this.series.name +'</b><br/>' +
                    Highcharts.dateFormat('%e - %b - %Y',
                                          new Date(this.x))
                + ' date, ' + this.y + ' Kg.';
            }
        }

You may want to also add the dateTimeLabelFormats object with the options you need for your dates, under the xAxis.

I did this example with your code