Search code examples
javascriptchartshighchartsaxisaxis-labels

Highcharts x-axis datetime - different format of first and last (boundaries) labels


How to set first and last datatime labels on x-axis in different format? I need this labels:

full datetime | time | time ... time | time | full datetime

Now I have the time everywhere.


Solution

  • By using the highcharts formatter for labels you can achieve what you seek. The formatter has two values this.isFirst and this.isLast which helps you distinguish start and end values.

    I made a simple example using this formatter:

    xAxis: {
      labels: {
        formatter: function() {
          if (this.isFirst || this.isLast) {
            return Highcharts.dateFormat('%a %e %b - %H %M %S', this.value);
          } else {
            return Highcharts.dateFormat('%H %M %S', this.value);
          }
        }
      }
    }
    

    Working example: http://jsfiddle.net/ewolden/n8o32ejx/

    DOCS on dateformat: http://www.php.net/manual/en/function.strftime.php

    API on highcharts formatter: http://api.highcharts.com/highcharts/xAxis.labels.formatter