Getting Started
First, we need to have a canvas in our page. It’s recommended to give the chart its own container for responsiveness.
Now that we have a canvas we can use, we need to include Chart.js in our page.
Now, we can create a chart. We add a script to our page:
<script>
const myChart = new Chart(
document.getElementById('myChart'),
config
);
</script>
It’s that easy to get started using Chart.js! From here you can explore the many options that can help you customise your charts with scales, tooltips, labels, colors, custom actions, and much more.
Here the sample above is presented with our sample block:
'February',
'March',
'April',
'May',
'June',
];
datasets: [{
label: 'My First dataset',
backgroundColor: 'rgb(255, 99, 132)',
borderColor: 'rgb(255, 99, 132)',
data: [0, 10, 5, 2, 20, 30, 45],
}]
Note
As you can see, some of the boilerplate needed is not visible in our sample blocks, as the samples focus on the configuration options.
All our examples are .