0👍
Your stockData
in chart.js is generate by javascript on browser
. But stockData
that really hold value that not undefine is generate by Nodejs
on backend. If you wanna use like this. First, you need to render your ejs
page, then send an ajax to server, get the response data. Then use that data you just receive to draw your chart
. Somethings like this:
axios.get('/search')
.then(function (response) {
let data = response.data;
new Chart(document.getElementById('line-chart'), {
type: 'line',
data: {
labels: [],
datasets: [{
data: [your_response_data_from_nodejs.open],
label: 'Blabla',
borderColor: '#52D0C4',
fill: false
}
]
},
options: {
title: {
display: true,
text: 'Blala '
}
}
});
})
.catch(function (error) {
throw new error;
});
Source:stackexchange.com