echarts vue 动画效果的水球图、波浪图教程

1、安装插件

前提是已经安装了echarts(我的版本是4.2.1)
npm install echarts-liquidfill --save
我安装了3.1.0版本的,结果运行时报错"TypeError: wave.ensureState is not a function"
在这里插入图片描述
原因:echarts版本和echarts-liquidfill的版本对应不上,根据下面的搭配版本安装就不会报错了

echarts@4.9.0 + echarts-liquidfill@2.0.6
echarts@5.2.0 + echarts-liquidfill@3.0.0

我安装了指定版本npm install echarts-liquidfill@2.0.6 --save

2、示例

2.1 效果图

里面的波浪有动画效果
在这里插入图片描述

2.2 代码实现

<template>
	<div id="main" style="width: 110px; height: 110px;"></div>
</template>
import echarts from 'echarts';
import 'echarts-liquidfill';

var chart = echarts.init(document.getElementById('architectureTarget'));
let option = {
  series: [{
    type: 'liquidFill',
    radius: '95%', // 波浪样式,不设置则为平直样式
    waveAnimation: true,
    direction: 'right', // 向右移动
    data: [{
      value: 0.85,
      itemStyle: {
        normal: {
          color: '#558bec'
        }
      },
    }],
    outline: {
      borderDistance: 7, // 外部轮廓与图表的距离
      itemStyle: {
        borderColor: '#558bec', // 边框的颜色
        borderWidth: 6, // 边框的宽度
        shadowBlur: 0, // 外部轮廓的阴影范围 一旦设置了内外都有阴影, 设为0可以去掉容器灰色背景
      },
    },
    label: { // 数据展示样式
      show: true,
      color: '#333',
      insideColor: '#fff',
      fontSize: 28,
      fontWeight: 600,
      align: 'center',
      baseline: 'middle',
      position: 'inside',
    },
  }]
};
option && charts.setOption(option);
  • 7
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在 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、付费专栏及课程。

余额充值