Easy Tutorial
❮ Chartjs Type Bar Chartjs Doughnut ❯

Chart.js Bubble Chart

Bubble charts are used to display the relationship between three variables.

The position of the bubbles is determined by the first two variables, corresponding to the X and Y axes, while the third parameter represents the size of the bubbles.

{
    // Value corresponding to the X axis
    x: number,

    // Value corresponding to the Y axis
    y: number,

    // Bubble radius in pixels
    r: number
}

The type property of the bubble chart is bubble, which describes the type of the chart.

const config = {
  type: 'bubble',
  data: data,
  options: {}
};

Next, we will create a simple bubble chart:

Example

const ctx = document.getElementById('myChart');
const data = {
  datasets: [{
    label: 'Bubble Chart Example',
    data: [{
      x: 20, // X axis
      y: 30, // Y axis
      r: 15  // Bubble radius
    }, {
      x: 30,
      y: 20,
      r: 20
    }, {
      x: 40,
      y: 10,
      r: 10
    }],
    backgroundColor: 'rgb(255, 99, 132)'
  }]
};
const config = {
  type: 'bubble', // Set chart type
  data: data,     // Set dataset
  options: {

  },
};
const myChart = new Chart(ctx, config);

The output of the above example is:

❮ Chartjs Type Bar Chartjs Doughnut ❯