I want to introduce a Packed circle chart (a variation of bubble chart which contains only the radius as its dimension). React Chartjs
and even Chartjs
support only Bubble chart but not Packed circle chart. Here is an example of the expected chart I want to add
Can I get something like this using react-chartjs
? For example, one needs to do something like below for a regular initiation of a bubble chart.
const defaultDatasets = [
{
label: ["China"],
backgroundColor: "rgba(255,221,50,0.2)",
borderColor: "rgba(255,221,50,1)",
data: [{
x: 735,
y: 50,
r: 15
}]
}, {
label: ["Denmark"],
backgroundColor: "rgba(60,186,159,0.2)",
borderColor: "rgba(60,186,159,1)",
data: [{
x: 116,
y: 50,
r: 10
}]
}, {
label: ["Germany"],
backgroundColor: "rgba(0,0,0,0.2)",
borderColor: "#000",
data: [{
x: 2116,
y: 50,
r: 15
}]
}
]
Since my requirement is a Packed circle chart, so I have two options.
- I could omit
x
andy
values. But then all bubbles get messed up. - I could randomise the
x
andy
values and hide the axes. But then the randomisation won't guarantee any bubble overlapping or may bring some bubbles concentrated to one point.
Is there any hack or workaround to show bubbles in a nice order like in the picture above?
EDIT: Apart from the great hack provided by @Offbeatmammal, there is another good library called Nivo that offers Packed circle chart that is free to use. Check it out https://nivo.rocks/circle-packing/canvas/