Bar not showing Bar chart + chart js

穿精又带淫゛_ 提交于 2019-12-25 01:53:07

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!