Chart.js


Chart.js is a free JavaScript library used to create charts in HTML. It's a straightforward visualization tool for JavaScript, offering various built-in chart types.

  • Scatter Plot
  • Line Chart
  • Bar Chart
  • Pie Chart
  • Donut Chart
  • Bubble Chart
  • Area Chart
  • Radar Chart
  • Mixed Chart

How to Use Chart.js?

1. Add a link to the providing CDN (Content Delivery Network):

<script
src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.4/Chart.js"
>

</script>

2. Add a <canvas> to where in the HTML you want to draw the chart:

<canvas id="myChart" style="width:100%;max-width:700px"></canvas>

The canvas element must have a unique id.

Typical Bar Chart Syntax:

const myChart = new Chart("myChart", {
  type: "bar",
  data: {},
  options: {}
});

Typical Line Chart Syntax:

const myChart = new Chart("myChart", {
  type: "line",
  data: {},
  options: {}
});

Bar Charts


Pie Charts


Doughnut Charts


Scatter Plots

House Prices vs. Size


Line Graphs

House Prices vs. Size

If you set the borderColor to zero, you can create ascatter plot instead of a line graph.


Multiple Lines


Linear Graphs


Function Graphs