问题
I am trying to build a Bar chart with a dataset with both x & y axes as time units. But I'm not able to bring bar on the chart. Can someone please check this and assist what am I doing wrong.
Here is the complete code. https://jsfiddle.net/sjabiulla/bkqpdjue/4/
Here is my js.
var chartData = {
datasets: [ {
type: 'bar',
label: 'Last Year',
backgroundColor: 'yellow',
borderColor: 'white',
fill:true,
data: [
{ x: '2017-01-06 00:00:00', y: '2017-01-06 04:15:30' },
{ x: '2017-01-07 00:00:00', y: '2017-01-06 07:39:30' },
{ x: '2017-01-08 00:00:00', y: '2017-01-06 06:39:30' },
{ x: '2017-01-09 00:00:00', y: '2017-01-06 08:00:30' },
{ x: '2017-01-10 00:00:00', y: '2017-01-06 05:39:30' },
{ x: '2017-01-11 00:00:00', y: '2017-01-06 09:39:30' },
]
}]
};
var ctx = document.getElementById('myChart').getContext('2d');
var chart = new Chart(ctx, {
type: 'bar',
data: chartData,
options: {
scales: {
xAxes: [{
type: 'time',
time: {
unit:'day'
}
}],
yAxes: [{
type: 'time',
time: {
unit:'hour'
},
ticks : {
reverse: true
}
}]
}
}
});
chart.canvas.parentNode.style.height = '380px';
chart.canvas.parentNode.style.width = '700px';
来源:https://stackoverflow.com/questions/56869758/bar-not-showing-bar-chart-chart-js