Chartjs-Chart.js not to be begin in Y-Axis

0👍

The easiest way to produce a margin between the Y axis and your first point is to add an empty string spacer in labels and a null value in data:

{
        type: 'line',
        data: {
            labels: ['', '2020-12-27','2020-12-28','2020-12-29','2020-12-31','2020-12-31','2020-01-01','2020-01-02','2020-01-03','2020-01-04','2020-01-05'],
            datasets: [{
                label: 'Weekly Revenue',
                data: [ null, 0, 100, 3000, 4000, 5000, 6000, 7000, 8000,9000,10000,],    
                fill: false,
                backgroundColor: [
                    'rgba(255, 99, 132, 0.2)',
                    'rgba(54, 162, 235, 0.2)',
                    'rgba(255, 206, 86, 0.2)',
                    'rgba(75, 192, 192, 0.2)',
                    'rgba(153, 102, 255, 0.2)',
                    'rgba(75, 192, 192, 0.2)',
                    'rgba(153, 102, 255, 0.2)',
                    'rgba(255, 159, 64, 0.2)'
                    
                ],
                borderColor: [
                    'rgba(255, 99, 132, 1)',
                    'rgba(54, 162, 235, 1)',
                    'rgba(255, 206, 86, 1)',
                    'rgba(75, 192, 192, 1)',
                    'rgba(153, 102, 255, 1)',
                    'rgba(75, 192, 192, 1)',
                    'rgba(153, 102, 255, 1)',
                    'rgba(255, 159, 64, 1)'
                ],
                borderWidth: 3
            },
        ]
        },
        options: {
         
            scales: {
                yAxes: [{
                    ticks: {
                        beginAtZero: true,
                        callback: function(value, index, values) {
                            return value.toLocaleString("en-PH",{style:"currency", currency:"PHP"});
                        }
                    }
                }]
            }
        }
    }

chart.js space on left

Leave a comment