Dmitriy Kupriyanov
Dmitriy Kupriyanov

Reputation: 479

Remove month from the axisX in highcharts.js

How remove month everywhere except at the first day of the month and leave the numbers days? Month must be written only one, first day each month. enter image description here Now my code

    xAxis: {
        type: 'datetime',
        labels: {
            overflow: 'justify'
        }
    },

Example https://jsfiddle.net/o5926erd/5/

Upvotes: 0

Views: 120

Answers (1)

Grzegorz Blachliński
Grzegorz Blachliński

Reputation: 5222

You can use labels.formatter function of your xAxis: http://api.highcharts.com/highcharts/xAxis.labels.formatter

formatter: function() {
  var xAxis = this.axis,
    previousMonth,
    date,
    newTicks = [],
    index,
    returnedString,
    months = this.chart.options.lang.months;

  Highcharts.each(xAxis.tickPositions, function(t) {
    date = new Date(t);
    if (date.getMonth() !== previousMonth) {
      previousMonth = date.getMonth();
      newTicks.push(t);
    }
  });

  index = newTicks.indexOf(this.value);
  date = new Date(this.value);
  returnedString = index >= 0 ? date.getDate() + '. ' + months[date.getMonth()] : date.getDate()
  return returnedString;
}

Here you can see an example how it can work: https://jsfiddle.net/o5926erd/8/

Upvotes: 1

Related Questions