You're specifying only the y scale. Update your options to specify both the x and y scales.
options: {
scales: {
x: {
beginAtZero: true,
},
y: {
beginAtZero: true,
},
},
}
Also, put the whole code in the window.onload, to ensure the script loads before the JS executes.