I am trying to add labels to each bubble in the bubble chart using chartjs-plugin-datalabels.
For each bubble, I want to show the label property of each object of data.dataset array
like "Grapefruit", "Lime". I am getting the value of r for all bubbles. Can we change this label?
I saw examples but did not get them right. I don't know what I'm doing wrong.
const data = {
datasets: [
{
label: 'Grapefruit',
data: [
{
x: 10,
y: 40,
r: 40,
},
],
backgroundColor: 'rgb(255, 99, 132)',
},
{
label: 'Lime',
data: [
{
x: 23,
y: 37,
r: 40,
},
],
backgroundColor: 'rgb(105, 89, 175)',
},
{
label: 'Coconut',
data: [
{
x: 26,
y: 33,
r: 40,
},
],
backgroundColor: 'rgb(249, 236, 61)',
},
{
label: 'Mango',
data: [
{
x: 40,
y: 40,
r: 40,
},
],
backgroundColor: 'rgb(255, 128, 0)',
},
],
};
const options = {
scales: { x: { display: false }, y: { display: false } },
maintainAspectRatio: false,
plugins: {
legend: {
display: false,
},
datalabels: {},
},
};
const App = () => {
return <Bubble data={data} height={415} width={310} options={options} />;
};