echarts 气泡图
时间: 2023-10-07 16:05:21 浏览: 231
ECharts 气泡图是一种数据可视化图表,可以用于展示多维度数据的散点图,每个气泡的大小和颜色可以表示不同的数据信息。下面是一个简单的示例代码:
```html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>ECharts 气泡图</title>
<!-- 引入 ECharts.js -->
<script src="https://cdn.jsdelivr.net/npm/echarts@5.1.2/dist/echarts.min.js"></script>
</head>
<body>
<!-- 为 ECharts 准备一个具备大小(宽高)的 DOM -->
<div id="chart" style="width: 600px;height:400px;"></div>
<script>
// 基于准备好的 DOM,初始化 ECharts 实例
var myChart = echarts.init(document.getElementById('chart'));
// 指定图表的配置项和数据
var option = {
title: {
text: '气泡图示例'
},
tooltip: {},
xAxis: {
type: 'value',
splitLine: {
lineStyle: {
type: 'dashed'
}
}
},
yAxis: {
type: 'value',
splitLine: {
lineStyle: {
type: 'dashed'
}
}
},
series: [{
data: [
[10.0, 8.04, 10],
[8.0, 6.95, 12],
[13.0, 7.58, 20],
[9.0, 8.81, 16],
[11.0, 8.33, 18],
[14.0, 9.96, 28],
[6.0, 7.24, 8],
[4.0, 4.26, 4],
[12.0, 10.84, 22],
[7.0, 4.82, 6],
[5.0, 5.68, 10],
],
type: 'scatter',
symbolSize: function (data) {
return Math.sqrt(data[2]) * 5;
},
label: {
emphasis: {
show: true,
formatter: function (param) {
return param.data[2];
},
position: 'top'
}
},
itemStyle: {
normal: {
color: 'rgba(50, 50, 255, 0.8)'
}
}
}]
};
// 使用刚指定的配置项和数据显示图表。
myChart.setOption(option);
</script>
</body>
</html>
```
在这个例子中,我们使用了 ECharts 的 `scatter` 类型来绘制气泡图,`symbolSize` 属性用于设置每个气泡的大小,`itemStyle` 属性用于设置每个气泡的颜色。同时,我们还使用了 `tooltip` 来展示每个气泡的数据信息。你可以根据自己的需求修改上述代码,来实现你自己的气泡图。
阅读全文
相关推荐
















