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.

Example Usage

  1. // For a bubble chart
  2. var myBubbleChart = new Chart(ctx, {
  3. type: 'bubble',
  4. data: data,
  5. options: options
  6. });

Dataset Properties

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
dataobject[]--required
hoverBackgroundColorColorYesYesundefined
hoverBorderColorColorYesYesundefined
hoverBorderWidthnumberYesYes1
hoverRadiusnumberYesYes4
hitRadiusnumberYesYes1
labelstring--undefined
pointStylestringYesYes'circle'
rotationnumberYesYes0
radiusnumberYesYes3

Labeling

label defines the text associated to the dataset and which appears in the legend and tooltips.

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
hoverBackgroundColorbubble background color when hovered.
hoverBorderColorbubble border color when hovered.
hoverBorderWidthbubble border width when hovered (in pixels).
hoverRadiusbubble additional radius when hovered (in pixels).
hitRadiusbubble additional radius for hit detection (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.defaults.bubble.

Data Structure

Bubble chart datasets need to contain a data array of points, each points 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.