Vue中使用echarts实现水球图

40 篇文章 5 订阅

效果:
在这里插入图片描述
在线调试网址:https://gallery.echartsjs.com/editor.html?c=xry0tUfcBe

echarts使用说明请查看:Vue中使用echarts实现常用图表总结

控制台输入安装echarts以及水球图
npm install echarts --save
npm install echarts-liquidfill --save
vue main.js中注册
import echarts from 'echarts'  //引入echarts
import 'echarts-liquidfill'
组件中使用
<template>
	<div class="hygrometer" ref="hygrometer"></div>
</template>
let hygrometer = this.$echarts.init(this.$refs.hygrometer)
option = {
            series: [{
                type: 'liquidFill',
                radius: '100px',
                data: [0.6],
                label: {
                    normal: {
                        color: '#fff',
                        insideColor: 'transparent',
                        textStyle: {
                            fontSize: 30,
                            fontWeight: 'bold',
                        }
                    }
                },
                color: [{
                    type: 'linear',
                    x: 0,
                    y: 1,
                    x2: 0,
                    y2: 0,
                    colorStops: [{
                        offset: 1,
                        color: ['#6a7feb'], // 0% 处的颜色
                    }, {
                        offset: 0,
                        color: ['#27e5f1'], // 100% 处的颜色
                    }],
                    global: false // 缺省为 false
                }],
                outline: {
                    show: true,
                    borderDistance: 5,
                    itemStyle: {
                        borderColor: 'rgba(67,209,100,1)',
                        borderWidth: 0
                    }
                }
            }]
        }
        console.log('option', option)
        hygrometer.setOption(option)
        

数据动态显示只需要调用后台接口,改变data的值即可
如果想做成水滴形状可以增加shape属性,利用svg的path路径,如

let option = {
            series: [{
                type: 'liquidFill',
                radius: '100px',
                data: [0.6],
                shape: 'path://M 100 120 a 140 140 0 1 0 198 0 c -26 -26 -44 -48 -44 -90 c -42 28 -128 64 -154 90"',
                label: {
                    normal: {
                        color: '#fff',
                        insideColor: 'transparent',
                        textStyle: {
                            fontSize: 30,
                            fontWeight: 'bold',
                        }
                    }
                },
                color: [{
                    type: 'linear',
                    x: 0,
                    y: 1,
                    x2: 0,
                    y2: 0,
                    colorStops: [{
                        offset: 1,
                        color: ['#6a7feb'], // 0% 处的颜色
                    }, {
                        offset: 0,
                        color: ['#27e5f1'], // 100% 处的颜色
                    }],
                    global: false // 缺省为 false
                }],
                outline: {
                    show: true,
                    borderDistance: 5,
                    itemStyle: {
                        borderColor: 'rgba(67,209,100,1)',
                        borderWidth: 0
                    }
                }
            }]
        }

在这里插入图片描述

如果大家想一起交流学习,共同进步,欢迎搜索公众号“是日前端”,输入关键词如:前端基础,获取资料,资料刚开始整理,目前还在完善中,点击交流群按钮进交流群,群里仅限技术交流、面试交流等,需要其它相关资料可以群里说,后续交流群人数增多会考虑特色内容,再次感谢大家的支持~

  • 7
    点赞
  • 35
    收藏
    觉得还不错? 一键收藏
  • 6
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值