源代码:
下载代码
AI 编程工具
点击运行
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>菜鸟教程(runoob.com)</title> <script src="https://lf26-cdn-tos.bytecdntp.com/cdn/expire-1-M/Chart.js/3.7.1/chart.js"></script> </head> <body> <canvas id="myChart" width="400" height="200"></canvas> <script> const ctx = document.getElementById('myChart'); const data = { datasets: [{ label: '气泡图实例', data: [{ x: 20, // X 轴 y: 30, // Y 轴 r: 15 // 气泡半径 }, { x: 30, y: 20, r: 20 }, { x: 40, y: 10, r: 10 }], backgroundColor: 'rgb(255, 99, 132)' }] }; const config = { type: 'bubble', // 设置图表类型 data: data, // 设置数据集 options: { }, }; const myChart = new Chart(ctx, config); </script> </body> </html>
运行结果: