水波球在项目中的引用

这篇博客展示了如何利用ECharts和ECharts-Liquidfill库创建一个动态的水波球图表。首先引入必要的依赖,然后定义组件的props,包括元素ID、数据对象、颜色等。在`onMounted`钩子中初始化图表,根据传入的数据计算百分比,并配置图表的系列、颜色、样式等属性。最后设置图表选项并渲染到页面上。
摘要由CSDN通过智能技术生成
<template>
  <div :id="props.elementID" class="w100 h100 charts-wrapper"></div>
</template>

<script setup lang="ts">
import * as echarts from 'echarts';
import 'echarts-liquidfill';
import { defineProps, onMounted, PropType } from 'vue';

interface DataParm {
  name: string;
  value: number;
  firstColor: string;
  lastColor: string;
}

const props = defineProps({
  elementID: {
    type: String,
    rquired: true
  },
  data: Object as PropType<DataParm>,
  firstColor: {
    type: String,
    rquired: true
  },
  lastColor: {
    type: String,
    rquired: true
  }
});
const createChart = (): void => {
  const chartDom = document.getElementById(props.elementID);
  const myChart = echarts.init(chartDom);
  console.log(props);
  let value = null;
  if ((props.data?.value ?? 0) > 100) {
    value = 100 / (props.data?.value ?? 0); // precent
  } else {
    value = (props.data?.value ?? 0) / 100; // precent
  }

  const firstColor = props.data?.firstColor ?? '';
  const lastColor = props.data?.lastColor ?? '';
  console.log(value);
  console.log(firstColor);
  console.log(lastColor);

  const option = {
    series: [
      {
        type: 'liquidFill',
        radius: '66%',
        center: ['50%', '50%'],
        // color: [lastColor, firstColor],
        data: [value, value], // data个数代表波浪数
        amplitude: 8,
        color: [
          {
            type: 'linear',
            x: 0,
            y: 1,
            x2: 0,
            y2: 0,
            colorStops: [
              {
                offset: 1,
                color: [firstColor] // 0% 处的颜色
              },
              {
                offset: 0,
                color: [lastColor] // 100% 处的颜色
              }
            ],
            global: false // 缺省为 false
          }
        ],
        // 图形样式
        itemStyle: {
          opacity: 0.74, // 波浪的透明度
          shadowBlur: 0 // 波浪的阴影范围
        },
        backgroundStyle: {
          borderWidth: 0,
          borderColor: '#448af9',
          color: '#0C4283'
        },
        label: {
          show: true,
          textStyle: {
            color: '#FFF',
            insideColor: '#12786f',
            fontSize: 20
          },
          formatter: () => `${props.data?.value ?? 0}个`
        },
        outline: {
          show: false
        }
      }
    ]
  };
  myChart.setOption(option);
};

onMounted(() => {
  createChart();
});
</script>
<style lang="scss" scoped></style>

需要在package.json加入依赖

"echarts": "^5.2.0",
"echarts-liquidfill": "^3.1.0",

Make A Pie - 水球图icon-default.png?t=LA92https://www.makeapie.com/editor.html?c=xQG69obZUy我引用的水波球的原型

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值