水球图组件封装

水球图组件封装

// 一、下载Echarts图表库和相关依赖文件(以下两种安装方式,可以随意选择)
// npm
npm i echarts@4
npm i echarts-liquidfill@2

<template>
  <div ref="liquidEchart" class="liquidData" />
</template>

<script>
// import echarts from 'echarts'
import 'echarts-liquidfill'
export default {
  name: '',
  props: {
    one: {
      type: Number,
      default: 0
      // required: true
    }
  },
  data() {
    return {
      chartsLiquid: '' // 初始化图表
    }
  },
  mounted() {
    this.initLiquidEchart()
  },
  methods: {
    initLiquidEchart() {
      setTimeout(() => {
        this.chartsLiquid = this.$echarts.init(this.$refs['liquidEchart'])
        // 把配置和数据放这里
        this.chartsLiquid.setOption({
          series: [{
            type: 'liquidFill',
            radius: '90%',
            data: [this.one / 100],
            color: 'rgba(67,209,100,1)',
            label: {
              normal: {
                color: '#000',
                insideColor: 'transparent',
                textStyle: {
                  fontSize: 16,
                  fontWeight: 'bold',
                  fontFamily: 'Microsoft YaHei'
                }
              }
            },
            outline: {
              show: true,
              borderDistance: 5,
              itemStyle: {
                borderColor: 'rgba(67,209,100,1)',
                borderWidth: 2
              }
            },
            backgroundStyle: {
              color: 'rgba(67,209,100,.3)'
            }
          }]

        })
      }, 50)
    }
  }
}

</script>

<style scoped>
.liquidData {
  width: 140px;
  height: 140px;
}
</style>
要在 Vue 中使用 Echarts 生成多个水球,你需要先安装 Echarts: ``` npm install echarts --save ``` 然后在 Vue 组件中引入 Echarts: ``` import echarts from 'echarts' ``` 接下来,你需要创建一个包含多个水球的容器,在 Vue 的 `mounted` 钩子函数中使用 Echarts 渲染水球: ``` <template> <div class="container"> <div class="chart" ref="chart1"></div> <div class="chart" ref="chart2"></div> <!-- 其他水球的容器 --> </div> </template> <script> import echarts from 'echarts' export default { mounted() { // 使用 Echarts 渲染水球 this.renderChart(this.$refs.chart1, 50) // 第一个水球,进度为 50% this.renderChart(this.$refs.chart2, 80) // 第二个水球,进度为 80% // 渲染其他水球 }, methods: { renderChart(container, percent) { const chart = echarts.init(container) chart.setOption({ series: [ { type: 'liquidFill', data: [percent / 100], color: ['#00a6ff', '#71c9ff', '#c7e1ff'], // 其他配置项 } ] }) } } } </script> ``` 在这个例子中,我们创建了多个水球的容器,并在 `mounted` 钩子函数中使用 `renderChart` 方法来渲染每个水球。在 `renderChart` 方法中,我们使用 Echarts 提供的 `liquidFill` 类型来绘制水球,通过传递不同的进度值来生成多个水球。 当然,你还可以根据自己的需求来调整代码,比如使用 Vue 组件封装水球,或者将数据传递给组件来动态生成水球等。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值