You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi,
I am very new to Chart.js and would like to learn how to implement it with ejs.
I tried using an example and changing the variables to use ejs variables but the chart does not render.
I have passed in simple arrays in the res.render() where the ejs file is, with the following variables:
const labels = ["A", "B", "C"];
const legend = "TEST";
const visits = [100, 88, 119];
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi,
I am very new to Chart.js and would like to learn how to implement it with ejs.
I tried using an example and changing the variables to use ejs variables but the chart does not render.
I have passed in simple arrays in the res.render() where the ejs file is, with the following variables:
const labels = ["A", "B", "C"];
const legend = "TEST";
const visits = [100, 88, 119];
Below is what is used in the ejs file.
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/chart.js"></script><script>
let ctx = document.getElementById("myChart");
let myChart = new Chart(ctx, {
type: 'bar',
data: {
labels: [<%= labels %>],
datasets: [{
label: <%=legend %>,
data: [<%= visits %>],
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: [{
ticks: {
beginAtZero:true
}
}]
}
}
});
</script>
Any idea how can I get it to render? It is always blank with no errors from console neither.
Beta Was this translation helpful? Give feedback.
All reactions