score:0

Accepted answer

for anyone who has any similar problem in future, i patched together a few solutions i found.

firstly, from here unix timestamp in javascript, i wrote the method:

            gettimestring: function(datestring) {
            var hours = new date(datestring).gethours();
            var mins = new date(datestring).getminutes();
            return math.round((new date("1970-02-01 " + hours + ":" + mins)).gettime());
        }

the important part here is to make sure you have the same day. not doing this will cause the chartjs graph to plot the times in different places on the y-axis, even if the hours are the same.

then from this stackoverflow question and the related plunker, in the chart options, i have:

{
                responsive: true,
                maintainaspectratio: false,
                scales: {
                    yaxes: [{
                        position: 'left',
                        ticks: {
                            callback: value => {
                                let date = moment(value);
                                if (date.diff(moment('1970-02-01 23:59:59'), 'minutes') === 0) {
                                    return null;
                                }
                                return date.format('h:mm');
                            },
                            stepsize: 3.6e+6
                        }
                    }]
                }, //end scales
                tooltips: {
                    callbacks: {
                        label: function(tooltipitem, data) {
                            let date = moment(tooltipitem.ylabel);
                            if (date.diff(moment('1970-02-01 23:59:59'), 'minutes') === 0) {
                                return null;
                            }
                            return date.format('h:mm');
                        }
                    }
                }
            }

pay attention to the callbacks. they will format the time, calculating the difference from a set time to the time you need plotted. in the first function, you could really use any day, it wouldn't matter, as long as it's the same day. the stepsize will display hourly intervals on the yaxis.


Related Query

More Query from same tag