score:0
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.
Source: stackoverflow.com
Related Query
- ChartJS Unix Time Values changed
- How do I add time sourced from an external source as an X axis to a ChartJS graph?
- Dynamically update values of a chartjs chart
- How to format x-axis time scale values in Chart.js v2
- how to plot multiple time series in chartjs where each time series has different times
- How get sum of total values in stackedBar ChartJs
- Chartjs displays numbers not time
- Display values outside of pie chart in chartjs
- ChartJS show gaps in time data
- Chartjs time plot xAxis shows year 1970
- Category scale on Y-axis and time on x-axis in bubble chart in Chartjs
- How to show data values or index labels in ChartJs (Latest Version)
- Chartjs real time graph x axis movement
- Line ChartJS empty / null values doesn't break the line
- How to add ChartJS code in Html2Pdf to view image
- Chartjs error : time scale: "time.format" is deprecated. Please use "time.parser" instead
- In bar chartjs report zero values are skipped so bars are invalid
- showing tooltips all the time in chartjs 2.4 not working
- chartjs time cartesian axis adapter and date library setup
- UnitStepSize for regular time interval with Chartjs
- Chartjs - Donut Chart label for small values not visible
- Chartjs bar-chart does not render when values are equal
- Using chartjs v2 to show categorical values on axis instead of numeric
- ChartJS shows date, but not time, when displaying labels in time axis
- Chartjs not working with d3 from csv source
- ChartJS not displaying time data using Moment.js
- Chartjs Bar chart shows undefined values
- Zoom chartjs with many X values
- Chartjs different row background colors according to Y axis values
- Force ChartJS to show Doughnut chart with null values
More Query from same tag
- Chart.js, PHP and JSON loop issue
- Mouse over on line chart data active other data-set in Chart.js
- How to change points/line based on value?
- Chart JS - Make chart scrollable if too much data
- How to change the Chart.js legend rectangles to squares
- How to trigger tooltip on legend hover?
- How to add links to chart.js (Doughnut Charts)?
- How to set a minimum width on the values in a doughnut chart?
- chart labels didn't shows in chartjs
- I wanna make this chart using chartjs In reactjs
- Chart.js canvas : can't center it
- Chart.js Cannot read property 'fontSize' of undefined
- chart.js won't display the chart in IE
- donut chart tooltip under center text
- angular-chart.js : issue with pointHoverBorderColor property for line chart
- Javascript Chart: How to hide the data
- How can I move a label left, paint it black, or remove it (Chart.JS)?
- JavaScript: Add Event Listener to an Event Listener
- update charjs dataset using react library
- ChartJS - Display one set of data at a time
- How to navigate tooltips popup by clicking custom buttons outside Chart.js v2 canvas?
- Add an image as background in ChartJS chart area [Not to canvas]
- How to increase the ghap between catergories or labels react-chartjs-2
- Chart.js: how to set multiple color to tick of y axes if > or < 0
- chart resizing in ng2-google-charts
- y=0 gridline (or axis?) not showing in chart.js
- ChartJS Pie Chart How default just show 2 legend datas
- Display chart data based on API call
- Is there a way to change color of a chart's grid in y-axis - ng2-charts
- Syntax to instantiate chart.js chart