Bubble Chart

A bubble chart is used to display three dimensions of data at the same time. The location of the bubble is determined by the first two dimensions and the corresponding horizontal and vertical axes. The third dimension is represented by the size of the individual bubbles.

Bubble Chart - 图1

config setup

  1. const config = {
  2. type: 'bubble',
  3. data: data,
  4. options: {}
  5. };
  1. const data = {
  2. datasets: [{
  3. label: 'First Dataset',
  4. data: [{
  5. x: 20,
  6. y: 30,
  7. r: 15
  8. }, {
  9. x: 40,
  10. y: 10,
  11. r: 10
  12. }],
  13. backgroundColor: 'rgb(255, 99, 132)'
  14. }]
  15. };

Dataset Properties

Namespaces:

  • data.datasets[index] - options for this dataset only
  • options.datasets.bubble - options for all bubble datasets
  • options.elements.point - options for all point elements
  • options - options for the whole chart

The bubble chart allows a number of properties to be specified for each dataset. These are used to set display properties for a specific dataset. For example, the colour of the bubbles is generally set this way.

NameTypeScriptableIndexableDefault
backgroundColorColorYesYes‘rgba(0, 0, 0, 0.1)’
borderColorColorYesYes‘rgba(0, 0, 0, 0.1)’
borderWidthnumberYesYes3
clipnumber|object|false--undefined
dataobject[]--required
drawActiveElementsOnTopbooleanYesYestrue
hoverBackgroundColorColorYesYesundefined
hoverBorderColorColorYesYesundefined
hoverBorderWidthnumberYesYes1
hoverRadiusnumberYesYes4
hitRadiusnumberYesYes1
labelstring--undefined
ordernumber--0
pointStylepointStyleYesYes‘circle’
rotationnumberYesYes0
radiusnumberYesYes3

All these values, if undefined, fallback to the scopes described in option resolution

General

NameDescription
clipHow to clip relative to chartArea. Positive value allows overflow, negative value clips that many pixels inside chartArea. 0 = clip at chartArea. Clipping can also be configured per side: clip: {left: 5, top: false, right: -2, bottom: 0}
drawActiveElementsOnTopDraw the active bubbles of a dataset over the other bubbles of the dataset
labelThe label for the dataset which appears in the legend and tooltips.
orderThe drawing order of dataset. Also affects order for tooltip and legend. more

Styling

The style of each bubble can be controlled with the following properties:

NameDescription
backgroundColorbubble background color.
borderColorbubble border color.
borderWidthbubble border width (in pixels).
pointStylebubble shape style.
rotationbubble rotation (in degrees).
radiusbubble radius (in pixels).

All these values, if undefined, fallback to the associated elements.point.* options.

Interactions

The interaction with each bubble can be controlled with the following properties:

NameDescription
hitRadiusbubble additional radius for hit detection (in pixels).
hoverBackgroundColorbubble background color when hovered.
hoverBorderColorbubble border color when hovered.
hoverBorderWidthbubble border width when hovered (in pixels).
hoverRadiusbubble additional radius when hovered (in pixels).

All these values, if undefined, fallback to the associated elements.point.* options.

Default Options

We can also change the default values for the Bubble chart type. Doing so will give all bubble charts created after this point the new defaults. The default configuration for the bubble chart can be accessed at Chart.overrides.bubble.

Data Structure

Bubble chart datasets need to contain a data array of points, each point represented by an object containing the following properties:

  1. {
  2. // X Value
  3. x: number,
  4. // Y Value
  5. y: number,
  6. // Bubble radius in pixels (not scaled).
  7. r: number
  8. }

Important: the radius property, r is not scaled by the chart, it is the raw radius in pixels of the bubble that is drawn on the canvas.

Internal data format

{x, y, _custom} where _custom is the radius.