Chart.js Bubble Chart

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

The position of a bubble is determined by the first two variables, corresponding to the X-axis and Y-axis, and the third parameter is the size of the bubble.

{
    // X 轴对应值
    x: number,

    // Y 轴对应值
    y: number,

    // 气泡半径,单位为像素
    r: number
}

The bubble chart'stypeproperty isbubble, type describes the chart type.

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

Next, let's 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);

Try it Yourself »

The above example outputs:

Other Extensions