简体   繁体   中英

How to add new Line but not in the first x axes

I want to add a new lines, but i want to add at the third x axes data. If i add new data in dataset, it always start from the beginning (in January in my data). i want a new line start from march to december, and another line starts from june to december.

let chart = new Chart(ctx, {
    type: 'line',
    data: {
        datasets: [{
            label: 'First dataset',
            data: [0, 20, 40, 50, 0, 20, 40, 50, 0, 20, 40, 50]
        }],
        labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']
    },
    options: {
        scales: {
            yAxes: [{
                ticks: {
                    suggestedMin: 50,
                    suggestedMax: 100
                }
            }]
        }
    }
});

You need to set default values for mouth witch don't want use example - 0 :

data: {
    datasets: [{
        label: 'First dataset',
        data: [0, 20, 40, 50, 0, 20, 40, 50, 0, 20, 40, 50]
    },
    {
        label: 'Second dataset',
        data: [0, 0, 0, 0, 0, 20, 40, 50, 0, 20, 40, 50]
    }],
    labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']
},

i founded exemple here we can use data value - null and it make empty space for this range

Not drawing null values using chart.js

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM