vue3之echarts水球异状图

vue3之echarts水球异状图

效果:
在这里插入图片描述

核心代码:

<template>
    <div class="container">
        <div ref="chartContainer" class="chart"></div>
        <div class="info">
            <div class="percent">{{ percent }}%</div>
        </div>
    </div>
</template>

<script setup>
import { ref, onMounted } from 'vue';
import * as echarts from 'echarts';
import 'echarts-liquidfill';

const chartContainer = ref(null);
const percent = ref(0.85);
const color = {
    x: 0,
    y: 0,
    x2: 0,
    y2: 1,
    colorStops: [
        {
            offset: 0,
            color: 'rgba(110, 238, 150, 0.4)', // 0% 处的颜色
        },
        {
            offset: 1,
            color: 'rgba(110, 238, 150, 0)', // 100% 处的颜色
        },
    ],
    global: false, // 缺省为 false
};

onMounted(() => {
    drawWaterball();
});

const drawWaterball = () => {
    const chart = echarts.init(chartContainer.value);

    const option = {
        series: [
            {
                type: 'liquidFill',
                radius: '96%',
                center: ['50%', '50%'],
                // 重点在这里,通过SVG 路径来实现
                shape: 'path://M245,233.8l-96.8,54.6c-11,6.2-24.6,6.1-35.5-0.3l-95.7-56.5c-10.9-6.4-17.6-18.2-17.4-30.9L0.7,89.5c0.1-12.7,7-24.3,18-30.5l96.8-54.6c11-6.2,24.6-6.1,35.5,0.3l95.7,56.5c10.9,6.4,17.6,18.2,17.4,30.9l-1.1,111.1C263,215.9,256.1,227.5,245,233.8z',
                data: [
                    {
                        value: percent.value,
                        itemStyle: {
                            normal: {
                                color,
                                borderWidth: 2,
                                borderColor: 'rgba(255, 233, 83, 0.4)',
                            },
                        },
                    },
                    {
                        value: percent.value,
                        itemStyle: {
                            normal: {
                                color,
                                borderWidth: 12,
                                borderColor: 'rgba(255, 233, 83, 0.2)',
                            },
                        },
                    },
                ], // data个数代表波浪数
                backgroundStyle: {
                    borderWidth: 0,
                    color: 'transparent',
                },
                label: {
                    normal: {
                        show: false,
                    },
                },
                outline: {
                    show: true,
                    itemStyle: {
                        borderWidth: 2,
                        borderColor: 'rgba(0,0,0,0)',
                    },
                    borderDistance: 0,
                },
            },
        ],
    };

    chart.setOption(option);
};
</script>

<style lang="scss" scoped>
.container {
    width: 293px;
    height: 320px;
    background: url('@/assets/img/bg.png') no-repeat 0 0;
    position: relative;

    .chart {
        width: 246px;
        height: 276px;
        position: absolute;
        left: 24px;
        top: 24px;
    }

    .info {
        width: 140px;
        font-family: 'flipper2017';
        color: rgba(255, 233, 83, 1);
        font-size: 43px;
        position: absolute;
        left: 50%;
        top: 50%;
        transform: translate(-50%, -50%);
    }
}
</style>

  • 4
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值