SeanSobey / ChartjsNodeCanvas

A node renderer for Chart.js using canvas.
MIT License
230 stars 75 forks source link

chartjs-node-canvas gridLines display : none not working. #70

Closed shm0007 closed 3 years ago

shm0007 commented 3 years ago

I'm trying to implement bar chart pdf for my express app. However, I noticed that I cannot change the display property of gridlines in X and Y axis. This code works for chart.js, but not in chartjs-node-canvas. var options = { scales: { xAxes: [{ gridLines: { display:false } }], yAxes: [{ gridLines: { display:false }
}] } }` Can anybody suggest any workaround? I need to remove the gridlines.

SeanSobey commented 3 years ago

Hi

Chart.js looks to have changed their API for this at some point. Your code looks to have been for an older version, which is most likely you issue. This code works for 2.9.4:

const configuration: ChartConfiguration = {
type: 'bar',
data: {
    labels: ['Red', 'Blue', 'Yellow', 'Green', 'Purple', 'Orange'],
    datasets: [{
        label: '# of Votes',
        data: [12, 19, 3, 5, 2, 3],
        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(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(255, 159, 64, 1)'
        ],
        borderWidth: 1
    }]
},
options: {
    scales: {
        yAxes: [{
            gridLines: {
                display: false,
            },
            ticks: {
                beginAtZero: true,
            } as any
        }],
        xAxes: [{
            gridLines: {
                display: false,
            },
        }]
    }
}
};