如何在Chart.js中显示直角

时间:2018-10-24 12:34:44

标签: javascript chart.js

我正在使用chartjs库以显示一些数据。以下代码负责使

new Chart(ctx, {
        type: 'line',
        data: {
            labels: ["00:00", "01:00", "02:00", "03:00",
                "04:00", "05:00", "06:00", "07:00",
                "08:00", "09:00", "10:00", "11:00",
                "12:00", "13:00", "14:00", "15:00",
                "16:00", "17:00", "18:00", "19:00",
                "20:00", "21:00", "22:00", "23:00", "24:00"],
            datasets: [{
                lineTension: 0,
                label: 'Values',
                data: [0,0,0,0,0,0,5,5,5,5,5,5,5,5,5,5,5,0,0,0,5,5,0,0,0],
                backgroundColor: ['rgba(149, 0, 193, 0.5)'],
                borderWidth: 1
            }]
        },
        elements: {line: {tension: 0}},
        options: {
            bezierCurve : false,
            scales: {yAxes: [{stacked: false, ticks: {fixedStepSize: 1}}]}
        }
    });

因此,我有一个这样的图表(没有红线): enter image description here

如何使Chart JS像红线一样显示直角数据?

1 个答案:

答案 0 :(得分:2)

只需添加

即可完成此操作
steppedLine: true

到您的数据集

另请参阅:How can I make a stepline or stepped chart in chart.js or D3?