score:15

Accepted answer

i have solved this problem by using ticks callback method and by setting autoskip false. however, i am not using timescale. in callback, you can pass your date and the desired format it will return the formatted date.
below is the screenshot for the same and the working sample code.
enter image description here

[sample-code]

var ctx = document.getelementbyid("chart_hr");
    function newdate(day, month) {
        return moment().date(day).month(month);
    }


var data = {
    labels: [newdate(8,8), newdate(10,8), newdate(12,8), newdate(17,8), newdate(21,8), newdate(23,8), newdate(28,8), newdate(1,9), newdate(4,9)],
    datasets: [
        {
            fill: false,
            data: [140, 180, 150, 150, 180, 150, 150, 150, 170],
            linetension: 0,
        },
        {
            fill: false,
            data: [80, 100, 80, 80, 80, 80, 100, 80, 100],
            linetension: 0,
        }
    ]
};
var options = {
    scales: {
        xaxes: [{
            ticks: {
                autoskip : false,
                callback: function(value, index, values) {
                    return new moment(value).format('dd mmm');
                }
            },
            gridlines : {
                display : false,
            }
        }],
        yaxes: [{
            ticks: {
                min: 50,
                max: 190,
               stepsize: 10
            }
        }],
    },
};
var mylinechart = new chart(ctx, {
    type: 'line',
    data: data,
    options: options
});

score:1

in order to only show the dates that appear in the dataset, use the distribution property set to 'series'. this will result in equal distances between points, removing extraneous gaps. note: this, unfortunately, only works for time series data. if you wish to produce labels for given datapoints for different values or different axis use the answer provided above using autoskip property and a callback function.

example:

options: {
  scales: {
    xaxes: [{
      type: 'time',
      distribution: 'series',
      time: {
        unit: 'day'
      }
    }]
  }
}

Related Query

More Query from same tag