Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Chart.js Bubble Chart

Chart.js Bubble Chart

A bubble chart is used to show the relationship among three variables.

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

{

    // X-axis corresponding value

    x: number,



    // Y-axis corresponding value

    y: number,



    // Bubble radius, unit is pixels

    r: number

}

The bubble chart's type The attribute is bubble, and 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 the chart type

  data

:

data

,

 

// Set the data set

  options

:

{

   

 

}

,

}

;

const

myChart

=

new

Chart

(

ctx

,

config

)

;

Try it »

The output of the above example is: