Getting Started

Let’s get started using Chart.js!

First, we need to have a canvas in our page.

  1. <canvas id="myChart"></canvas>

Now that we have a canvas we can use, we need to include Chart.js in our page.

  1. <script src="https://cdn.jsdelivr.net/npm/[email protected]"></script>

Now, we can create a chart. We add a script to our page:

  1. var ctx = document.getElementById('myChart').getContext('2d');
  2. var chart = new Chart(ctx, {
  3. // The type of chart we want to create
  4. type: 'line',
  5. // The data for our dataset
  6. data: {
  7. labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'],
  8. datasets: [{
  9. label: 'My First dataset',
  10. backgroundColor: 'rgb(255, 99, 132)',
  11. borderColor: 'rgb(255, 99, 132)',
  12. data: [0, 10, 5, 2, 20, 30, 45]
  13. }]
  14. },
  15. // Configuration options go here
  16. options: {}
  17. });

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.

All our examples are available online but you can also download the Chart.js.zip archive attached to every release to experiment with our samples locally from the /samples folder.