Chartjs-Tick โ€“ no negative

0๐Ÿ‘

โœ…

I ended up doing this as I only have a single dataset in each graph. Happy to know if there is a better way.

function addData(chart, label, data) {
    chart.data.labels.push(label);
    chart.data.datasets.forEach((dataset) => {
        dataset.data.push(data);
        if (dataset.data.every(item => item === 0)) {
            chart.options.scales.yAxes[0].ticks.min = 0;
        } else {
            chart.options.scales.yAxes[0].ticks.min = undefined;
        }
    });
    chart.update();
}

Leave a comment