Hey @avivtech thanks a lot for sharing this! Super helpful. I can manage to get one chartjs graph to work easily, but it gets more complicated when I want to display more than one chartjs graph on a page.
The only way I managed to get more than 1 graph on the page is to add them to same embed element, see the code below:
<canvas id="chart1"></canvas>
<canvas id="chart2"></canvas>
<script>
const labels = [
'January',
'February',
'March',
'April',
'May',
'June',
];
const data = {
labels: labels,
datasets: [{
label: 'My First dataset',
backgroundColor: 'rgb(255, 99, 132)',
borderColor: 'rgb(255, 99, 132)',
data: [0, 10, 5, 2, 20, 30, 45],
}]
};
const config = {
type: 'line',
data,
options: {}
};
var myChart1 = new Chart(
document.getElementById('chart1'),
config
);
var myChart2 = new Chart(
document.getElementById('chart2'),
config
);
I added the script source in the page header, via the page settings custom code, inside tag.
My problem is that if I try to have the graphs (with different id etc.) into separate embed elements, only the first chartjs graph is displayed… This is of course very limiting in terms of design/layout for the page.
Is this an issue with Webflow or am I missing something?