[Chartjs]-Laravel 5.1 format date array for chart.js data

0πŸ‘

βœ…

The only way I managed to achieve this was formatting the date inside my controller before sending it to my view. I will post code later when I’m not at work πŸ™‚

1πŸ‘

I would say format it in ChartJS itself if your purely looking to change it as part of the presentation. If you look at this question we see that we can format our labels for data points using something like.

scaleLabel: function (valuePayload) {
    return Number(valuePayload.value).toFixed(2).replace('.',',') + '$';
}

now in your case you could maybe do something like

scaleLabel: function (value) {
    return moment(value).format("ddd, hA"); ;
}

to format date in a nice way. Making use of momentjs in this case.

Warning: Above is not tested I’ve never done this with ChartJS but in theory it should work.

Leave a comment