Stripped personal data from development repository
Samo Penic
2019-02-20 83c3f647c35477564b77cbc5b36d37d793d5442a
commit | author | age
83c3f6 1 # Bubble Chart
SP 2
3 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.
4
5 {% chartjs %}
6 {
7     "type": "bubble",
8     "data": {
9         "datasets": [{
10             "label": "First Dataset",
11             "data": [{
12                 "x": 20,
13                 "y": 30,
14                 "r": 15
15             }, {
16                 "x": 40,
17                 "y": 10,
18                 "r": 10
19             }],
20             "backgroundColor": "rgb(255, 99, 132)"
21         }]
22     },
23 }
24 {% endchartjs %}
25
26 ## Example Usage
27
28 ```javascript
29 // For a bubble chart
30 var myBubbleChart = new Chart(ctx,{
31     type: 'bubble',
32     data: data,
33     options: options
34 });
35 ```
36
37 ## Dataset Properties
38
39 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.
40
41 | Name | Type | [Scriptable](../general/options.md#scriptable-options) | [Indexable](../general/options.md#indexable-options) |  Default
42 | ---- | ---- | :----: | :----: | ----
43 | [`backgroundColor`](#styling) | [`Color`](../general/colors.md) | Yes | Yes | `'rgba(0,0,0,0.1)'`
44 | [`borderColor`](#styling) | [`Color`](../general/colors.md) | Yes | Yes | `'rgba(0,0,0,0.1)'`
45 | [`borderWidth`](#styling) | `Number` | Yes | Yes | `3`
46 | [`data`](#data-structure) | `Object[]` | - | - | **required**
47 | [`hoverBackgroundColor`](#interactions) | [`Color`](../general/colors.md) | Yes | Yes | `undefined`
48 | [`hoverBorderColor`](#interactions) | [`Color`](../general/colors.md) | Yes | Yes | `undefined`
49 | [`hoverBorderWidth`](#interactions) | `Number` | Yes | Yes | `1`
50 | [`hoverRadius`](#interactions) | `Number` | Yes | Yes | `4`
51 | [`hitRadius`](#interactions) | `Number` | Yes | Yes | `1`
52 | [`label`](#labeling) | `String` | - | - | `undefined`
53 | [`pointStyle`](#styling) | `String` | Yes | Yes | `circle`
54 | [`rotation`](#styling) | `Number` | Yes | Yes | `0`
55 | [`radius`](#styling) | `Number` | Yes | Yes | `3`
56
57 ### Labeling
58
59 `label` defines the text associated to the dataset and which appears in the legend and tooltips.
60
61 ### Styling
62
63 The style of each bubble can be controlled with the following properties:
64
65 | Name | Description
66 | ---- | ----
67 | `backgroundColor` | bubble background color
68 | `borderColor` | bubble border color
69 | `borderWidth` | bubble border width (in pixels)
70 | `pointStyle` | bubble [shape style](../configuration/elements#point-styles)
71 | `rotation` | bubble rotation (in degrees)
72 | `radius` | bubble radius (in pixels)
73
74 All these values, if `undefined`, fallback to the associated [`elements.point.*`](../configuration/elements.md#point-configuration) options.
75
76 ### Interactions
77
78 The interaction with each bubble can be controlled with the following properties:
79
80 | Name | Description
81 | ---- | -----------
82 | `hoverBackgroundColor` | bubble background color when hovered
83 | `hoverBorderColor` | bubble border color hovered
84 | `hoverBorderWidth` | bubble border width when hovered (in pixels)
85 | `hoverRadius` | bubble **additional** radius when hovered (in pixels)
86 | `hitRadius` | bubble **additional** radius for hit detection (in pixels)
87
88 All these values, if `undefined`, fallback to the associated [`elements.point.*`](../configuration/elements.md#point-configuration) options.
89
90 ## Default Options
91
92 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`.
93
94 ## Data Structure
95
96 Bubble chart datasets need to contain a `data` array of points, each points represented by an object containing the following properties:
97
98 ```javascript
99 {
100     // X Value
101     x: <Number>,
102
103     // Y Value
104     y: <Number>,
105
106     // Bubble radius in pixels (not scaled).
107     r: <Number>
108 }
109 ```
110
111 **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.