2021-04-02 14:04:39 +02:00
|
|
|
# Bubble
|
|
|
|
|
|
|
|
```js chart-editor
|
2022-08-18 13:34:35 +02:00
|
|
|
// <block:setup:1>
|
|
|
|
const DATA_COUNT = 7;
|
|
|
|
const NUMBER_CFG = {count: DATA_COUNT, rmin: 5, rmax: 15, min: 0, max: 100};
|
|
|
|
|
|
|
|
const data = {
|
|
|
|
datasets: [
|
|
|
|
{
|
|
|
|
label: 'Dataset 1',
|
|
|
|
data: Utils.bubbles(NUMBER_CFG),
|
|
|
|
borderColor: Utils.CHART_COLORS.red,
|
|
|
|
backgroundColor: Utils.transparentize(Utils.CHART_COLORS.red, 0.5),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: 'Dataset 2',
|
|
|
|
data: Utils.bubbles(NUMBER_CFG),
|
|
|
|
borderColor: Utils.CHART_COLORS.orange,
|
|
|
|
backgroundColor: Utils.transparentize(Utils.CHART_COLORS.orange, 0.5),
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
// </block:setup>
|
|
|
|
|
2021-04-02 14:04:39 +02:00
|
|
|
// <block:actions:2>
|
|
|
|
const actions = [
|
|
|
|
{
|
|
|
|
name: 'Randomize',
|
|
|
|
handler(chart) {
|
|
|
|
chart.data.datasets.forEach(dataset => {
|
2022-08-18 13:34:35 +02:00
|
|
|
dataset.data = Utils.bubbles({count: DATA_COUNT, rmin: 5, rmax: 15, min: 0, max: 100});
|
2021-04-02 14:04:39 +02:00
|
|
|
});
|
|
|
|
chart.update();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Add Dataset',
|
|
|
|
handler(chart) {
|
2022-08-18 13:34:35 +02:00
|
|
|
const chartData = chart.data;
|
|
|
|
const dsColor = Utils.namedColor(chartData.datasets.length);
|
2021-04-02 14:04:39 +02:00
|
|
|
const newDataset = {
|
2022-08-18 13:34:35 +02:00
|
|
|
label: 'Dataset ' + (chartData.datasets.length + 1),
|
2021-04-02 14:04:39 +02:00
|
|
|
backgroundColor: Utils.transparentize(dsColor, 0.5),
|
|
|
|
borderColor: dsColor,
|
2022-08-18 13:34:35 +02:00
|
|
|
data: Utils.bubbles({count: DATA_COUNT, rmin: 5, rmax: 15, min: 0, max: 100}),
|
2021-04-02 14:04:39 +02:00
|
|
|
};
|
|
|
|
chart.data.datasets.push(newDataset);
|
|
|
|
chart.update();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Add Data',
|
|
|
|
handler(chart) {
|
2022-08-18 13:34:35 +02:00
|
|
|
const chartData = chart.data;
|
|
|
|
if (chartData.datasets.length > 0) {
|
2021-04-02 14:04:39 +02:00
|
|
|
|
2022-08-18 13:34:35 +02:00
|
|
|
for (let index = 0; index < chartData.datasets.length; ++index) {
|
|
|
|
chartData.datasets[index].data.push(Utils.bubbles({count: 1, rmin: 5, rmax: 15, min: 0, max: 100})[0]);
|
2021-04-02 14:04:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
chart.update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Remove Dataset',
|
|
|
|
handler(chart) {
|
|
|
|
chart.data.datasets.pop();
|
|
|
|
chart.update();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Remove Data',
|
|
|
|
handler(chart) {
|
|
|
|
chart.data.datasets.forEach(dataset => {
|
|
|
|
dataset.data.pop();
|
|
|
|
});
|
|
|
|
|
|
|
|
chart.update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
];
|
|
|
|
// </block:actions>
|
|
|
|
|
|
|
|
// <block:config:0>
|
|
|
|
const config = {
|
|
|
|
type: 'bubble',
|
|
|
|
data: data,
|
|
|
|
options: {
|
|
|
|
responsive: true,
|
|
|
|
plugins: {
|
|
|
|
legend: {
|
|
|
|
position: 'top',
|
|
|
|
},
|
|
|
|
title: {
|
|
|
|
display: true,
|
|
|
|
text: 'Chart.js Bubble Chart'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
};
|
|
|
|
// </block:config>
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
actions: actions,
|
|
|
|
config: config,
|
|
|
|
};
|
|
|
|
```
|
2022-05-21 17:02:13 +02:00
|
|
|
|
|
|
|
## Docs
|
2022-08-18 13:34:35 +02:00
|
|
|
* [Bubble](../../charts/bubble.html)
|