在 Echarts 中绘制水球图

Web

Liquid Fill 是一个基于 Echats 的插件,使用它可以绘制出水球图。

引入

1
2
<script src='echarts.js'></script>  // 必须得使用Echarts
<script src='echarts-liquidfill.js'></script>

使用 npm 安装

1
2
$ npm install echarts
$ npm install echarts-liquidfill

引入:

1
2
import * as echarts from 'echarts';
import 'echarts-liquidfill'

例子

最基本的设置

type设置为'liquidFill'

1
2
3
4
5
6
var option = {
series: [{
type: 'liquidFill',
data: [0.6]
}]
};

创建多个波浪

data中添加更多数据:

1
2
3
4
5
6
var option = {
series: [{
type: 'liquidFill',
data: [0.6, 0.5, 0.4, 0.3]
}]
};

API

默认的配置:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
{
data: [],

color: ['#294D99', '#156ACF', '#1598ED', '#45BDFF'],
center: ['50%', '50%'],
radius: '50%',
amplitude: '8%',
waveLength: '80%',
phase: 'auto',
period: 'auto',
direction: 'right',
shape: 'circle',

waveAnimation: true,
animationEasing: 'linear',
animationEasingUpdate: 'linear',
animationDuration: 2000,
animationDurationUpdate: 1000,

outline: {
show: true,
borderDistance: 8,
itemStyle: {
color: 'none',
borderColor: '#294D99',
borderWidth: 8,
shadowBlur: 20,
shadowColor: 'rgba(0, 0, 0, 0.25)'
}
},

backgroundStyle: {
color: '#E3F7FF'
},

itemStyle: {
opacity: 0.95,
shadowBlur: 50,
shadowColor: 'rgba(0, 0, 0, 0.4)'
},

label: {
show: true,
color: '#294D99',
insideColor: '#fff',
fontSize: 50,
fontWeight: 'bold',

align: 'center',
baseline: 'middle'
position: 'inside'
},

emphasis: {
itemStyle: {
opacity: 0.8
}
}
}

官方文档

项目地址:echarts-liquidfill

本文作者:Kiro

本文链接: https://www.kiro.cc/2021/10/echarts-liquidfill/