【echarts水球图】动态展示百分比数值

效果图:

使用技术:echarts5.2.0+echarts-liquidfill3.1.0(必需)
注:echarts5必须liquidfill3以上;liquidfill2使用echarts4
使用:
<template><div id="circleChart1" style="width: 80%; height: 100px;"/></template>

<script setup lang="ts">
import {createChartOptions} from './CircleChart';
import * as echarts from 'echarts';

const fillPercentage = ref<number>(0.66);
onMounted(() => {
	const circleChart1 = echarts.init(document.getElementById("circleChart1") as HTMLDivElement);
	circleChart1.setOption(createChartOptions(fillPercentage.value));
})
</script>
ts部分:
import 'echarts-liquidfill';

type ItemStyle = {
	normal: {
		color: string;
		borderWidth: number;
		borderColor: string;
	};
};

type DataItem = {
	name: string;
	value: number;
	itemStyle: ItemStyle;
};

function Pie(): DataItem[] {
	const dataArr: DataItem[] = [];
	for (let i = 0; i < 150; i++) {
		if (i % 2 === 0) {
			dataArr.push({
				name: (i + 1).toString(),
				value: 50,
				itemStyle: {
					normal: {
						color: "red",
						borderWidth: 0,
						borderColor: "rgba(0,0,0,0)",
					},
				},
			});
		} else {
			dataArr.push({
				name: (i + 1).toString(),
				value: 100,
				itemStyle: {
					normal: {
						color: "rgba(0,0,0,0)",
						borderWidth: 0,
						borderColor: "rgba(0,0,0,0)",
					},
				},
			});
		}
	}
	return dataArr;
}

function createChartOptions(fillPercentage:number) {
	return {
		backgroundColor: 'transparent', // 画布背景色
		series: [
			{
				type: 'liquidFill',
				radius: '85%',
				center: ['50%', '50%'],
				data: [
					fillPercentage,
					{
						value: fillPercentage,
						direction: 'left',
					},
				],
				backgroundStyle: {
					borderWidth: 1,
					color: 'rgb(255,255,255,0.2)',
				},
				amplitude: '6%',
				color: [
					{
						type: 'linear',
						x: 0,
						y: 0,
						x2: 0,
						y2: 1,
						colorStops: [
							{
								offset: 1,
								color: '#FFB200',
							},
							{
								offset: 0,
								color: '#FF8A83',
							},
						],
						globalCoord: false,
					},
				],
				label: {
					normal: {
						formatter: `${fillPercentage * 100}{d|%}`,
						rich: {
							d: {
								fontSize: 20,
							},
						},
						textStyle: {
							fontSize: 18,
							color: '#FFFFFF',
						},
					},
				},
				outline: {
					show: false,
				},
			},


			{
				type: 'pie',
				z: 1,
				zlevel: -2,
				radius: ['97%', '100%'],
				center: ['50%', '50%'],
				hoverAnimation: false,
				clockWise: false,
				itemStyle: {
					normal: {
						borderWidth: 1,
						color: 'rgb(255,255,255,0.2)',
					},
				},
				label: {
					show: false,
				},
				data: [100],
			},

		],
	};
}

export {Pie, createChartOptions};

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值