Please use this in an HTML to URL column, and use Web Embed to display it.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Chart.js Bubble Chart with Dynamic Central Line</title>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chartjs-plugin-annotation"></script>
<script src="https://cdn.jsdelivr.net/npm/chartjs-plugin-datalabels"></script>
</head>
<body>
<canvas id="myChart" width="600" height="1200"></canvas>
<script>
Chart.register(ChartDataLabels);
const ctx = document.getElementById('myChart').getContext('2d');
const data = [
{ label: 'name1', data: [{ x: 46, y: 26, r: 11 }], backgroundColor: 'rgba(255, 99, 132, 0.5)' },
{ label: 'name2', data: [{ x: 7, y: 37, r: 13 }], backgroundColor: 'rgba(54, 162, 235, 0.5)' },
{ label: 'name3', data: [{ x: 43, y: 19, r: 15 }], backgroundColor: 'rgba(255, 206, 86, 0.5)' },
{ label: 'name4', data: [{ x: 5, y: 40, r: 9 }], backgroundColor: 'rgba(75, 192, 192, 0.5)' },
{ label: 'name5', data: [{ x: 10, y: 19, r: 19 }], backgroundColor: 'rgba(153, 102, 255, 0.5)' },
{ label: 'name6', data: [{ x: 100, y: 45, r: 12 }], backgroundColor: 'rgba(255, 159, 64, 0.5)' },
{ label: 'name7', data: [{ x: 15, y: 45, r: 30 }], backgroundColor: 'rgba(255, 99, 132, 0.5)' },
{ label: 'name8', data: [{ x: 2, y: 14, r: 4 }], backgroundColor: 'rgba(54, 162, 235, 0.5)' },
{ label: 'name9', data: [{ x: 3, y: 42, r: 5 }], backgroundColor: 'rgba(255, 206, 86, 0.5)' },
{ label: 'name10', data: [{ x: 47, y: 67, r: 2 }], backgroundColor: 'rgba(75, 192, 192, 0.5)' },
{ label: 'name11', data: [{ x: 3, y: 33, r: 5 }], backgroundColor: 'rgba(153, 102, 255, 0.5)' },
];
const xValues = data.map(item => item.data[0].x);
const yValues = data.map(item => item.data[0].y);
const xAverage = xValues.reduce((a, b) => a + b) / xValues.length;
const yAverage = yValues.reduce((a, b) => a + b) / yValues.length;
const config = {
type: 'bubble',
data: {
datasets: data,
},
options: {
plugins: {
legend: {
display: false,
},
tooltip: {
enabled: true, // Enable tooltips
callbacks: {
label: function(context) {
const point = context.raw;
return [
`Name: ${context.dataset.label}`,
`X: ${point.x}`,
`Y: ${point.y}`,
`Size: ${point.r}`
];
}
}
},
datalabels: {
color: 'black',
display: true,
font: {
weight: 'bold',
size: 12
},
formatter: function(value, context) {
return context.dataset.label;
},
anchor: 'bottom',
align: 'bottom',
offset: 5
},
annotation: {
annotations: {
verticalLine: {
type: 'line',
xMin: xAverage,
xMax: xAverage,
borderColor: 'black',
borderWidth: 3,
},
horizontalLine: {
type: 'line',
yMin: yAverage,
yMax: yAverage,
borderColor: 'black',
borderWidth: 3,
},
},
}
},
responsive: true,
maintainAspectRatio: false,
scales: {
x: {
min: 0,
max: 100,
position: 'bottom',
grid: {
color: 'black',
borderColor: 'black',
drawBorder: true,
drawOnChartArea: false,
drawTicks: false,
},
ticks: {
callback: function(value, index, values) {
if (value === 0) return null;
return value;
}
}
},
y: {
min: 0,
max: 70,
position: 'left',
grid: {
color: 'black',
borderColor: 'black',
drawBorder: true,
drawOnChartArea: false,
drawTicks: false,
},
ticks: {
callback: function(value, index, values) {
if (value === 0) return '0';
return value;
}
}
}
}
},
};
new Chart(ctx, config);
</script>
</body>
</html>