npm https://www.npmjs.com/package/echarts-liquidfill
github文档 https://github.com/ecomfe/echarts-liquidfill#readme
在线 demo https://ecomfe.github.io/echarts-liquidfill/example/

echarts 水球图案例
https://www.makeapie.com/explore.html#sort=rank~timeframe=all~query=liquidFill~author=all
https://www.makeapie.com/explore.html#tags=liquidFill~sort=rank~timeframe=all~author=all

echarts水球图 - 图1

  1. yarn add echarts-liquidfill
  2. npm install echarts
  3. npm install echarts-liquidfill

水波纹效果

WaterWave 实现水位波浪动画,也就是波浪(或者水装在容器中)的侧面图
https://github.com/YingshanDeng/WaterWave
echarts水球图 - 图2

正弦函数 http://objcer.com/2015/02/19/WaterWave/
echarts水球图 - 图3

水球图原理

修改了echarts的 series

  1. const echarts = require('echarts/lib/echarts');
  2. echarts.extendSeriesModel({
  3. type: 'series.liquidFill',
  4. visualColorAccessPath: 'textStyle.mormal.color',
  5. });

echarts水球图 - 图4

antv水波图

http://antv-2018.alipay.com/zh-cn/g2/3.x/demo/other/liquid-fill-gauge.html
echarts水球图 - 图5

vue水球图

echarts水球图 - 图6
https://github.com/acdseen/waterWaves

  1. yarn add waterwaves

use

  1. import WaterWaves from 'waterwaves'
  2. Vue.use(WaterWaves)
  3. <WaterWaves v-model="level" />
  4. <canvas id="canvas" width="400px" height="400px"></canvas>
  5. <script>
  6. var option={
  7. cW:130,
  8. cH:130,
  9. baseY:50,
  10. nowRange:0
  11. };
  12. var water=new WaterPolo('canvas',option);
  13. </script>

vue

echarts水球图 - 图7

  1. <template>
  2. <div class="chart" ref="box"/>
  3. </template>
  4. <script>
  5. import * as echarts from 'echarts';
  6. import 'echarts-liquidfill';
  7. import {
  8. defineComponent, getCurrentInstance, onMounted,
  9. } from 'vue';
  10. function getOptions() {
  11. return [
  12. {
  13. type: 'liquidFill',
  14. data: [0.6],
  15. }];
  16. }
  17. export default defineComponent({
  18. setup() {
  19. onMounted(() => {
  20. const { ctx } = getCurrentInstance();
  21. const element = ctx.$refs.box;
  22. // 基于准备好的dom,初始化echarts实例
  23. const myChart = echarts.init(element);
  24. // 绘制图表
  25. myChart.setOption({
  26. series: getOptions(),
  27. });
  28. });
  29. }
  30. });
  31. </script>
  32. <style scoped>
  33. .chart {
  34. height: 400px;
  35. }
  36. </style>

echarts水球图 - 图8

  1. <template>
  2. <div class="chart" ref="box"/>
  3. </template>
  4. <script>
  5. import * as echarts from 'echarts';
  6. import 'echarts-liquidfill';
  7. import {
  8. defineComponent, getCurrentInstance, onMounted,
  9. } from 'vue';
  10. function getOptions() {
  11. const max = 500; // 满刻度大小
  12. const score = 89;
  13. const scorePer = score / 100;
  14. const data = max * scorePer;
  15. return {
  16. backgroundColor: '#fff',
  17. title: {
  18. top: '47%',
  19. left: 'center',
  20. text: `${score} 分`,
  21. textStyle: {
  22. color: '#fff',
  23. fontStyle: 'normal',
  24. fontWeight: 'normal',
  25. fontSize: 32
  26. }
  27. },
  28. series: [{
  29. type: 'liquidFill',
  30. itemStyle: {
  31. opacity: 0.8, // 波浪的透明度
  32. shadowBlur: 10, // 波浪的阴影范围
  33. shadowColor: '#FFB931'// 阴影颜色
  34. },
  35. radius: '80%',
  36. // 水波
  37. color: [new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
  38. offset: 0,
  39. color: '#FE8704'
  40. },
  41. {
  42. offset: 1,
  43. color: '#FFB931'
  44. }
  45. ])],
  46. data: [{
  47. value: scorePer,
  48. }],
  49. center: ['50%', '50%'],
  50. backgroundStyle: {
  51. color: '#fff'
  52. },
  53. label: {
  54. normal: {
  55. formatter: '',
  56. textStyle: {
  57. fontSize: 12
  58. }
  59. }
  60. },
  61. outline: {
  62. itemStyle: {
  63. borderColor: 'transparent',
  64. borderWidth: 5
  65. },
  66. borderDistance: 0
  67. }
  68. },
  69. {
  70. color: ['#FF8B00', 'transparent'], // 外环线
  71. type: 'pie',
  72. center: ['50%', '50%'],
  73. radius: ['80%', '82%'],
  74. hoverAnimation: false,
  75. data: [{
  76. name: '',
  77. value: data,
  78. label: {
  79. show: false,
  80. position: 'center',
  81. color: '#fff',
  82. fontSize: 38,
  83. fontWeight: 'bold',
  84. formatter () {
  85. return data;
  86. }
  87. }
  88. },
  89. { // 画剩余的刻度圆环
  90. name: '',
  91. value: max - data,
  92. label: {
  93. show: false
  94. },
  95. labelLine: {
  96. show: false
  97. }
  98. }
  99. ]
  100. }
  101. ]
  102. };
  103. }
  104. export default defineComponent({
  105. setup() {
  106. onMounted(() => {
  107. const { ctx } = getCurrentInstance();
  108. const element = ctx.$refs.box;
  109. console.log('ctx', element);
  110. // 基于准备好的dom,初始化echarts实例
  111. const myChart = echarts.init(element);
  112. // 绘制图表
  113. myChart.setOption(getOptions());
  114. });
  115. }
  116. });
  117. </script>
  118. <style scoped>
  119. .chart {
  120. height: 400px;
  121. }
  122. </style>