vue使用echarts

9 篇文章 0 订阅
8 篇文章 0 订阅

一、安装echarts

npm install echarts -S
或使用淘宝的镜像
npm install -g cnpm --registry=https://registry.npm.taobao.org
cnpm install echarts -S

二、引入依赖

let echarts = require('echarts')
Vue.prototype.$echarts = echarts

这里需要注意引入echarts的时候如果用“import echarts from ‘echarts’”会报以下错误:
[Vue warn]: Error in mounted hook: “TypeError: Cannot read properties of undefined (reading ‘init’)”
改用“let echarts = require(‘echarts’)“引入就行了

三、 方法

export default {
  name: 'index',
  data () {
    return {
    }
  },
  mounted(){
    this.myChart()
  },
  methods: {
    myChart(){
      let myChart = this.$echarts.init(document.getElementById('myChart'))
      // 绘制图表
      var datas = {
        value: 95,
        company: "%",
        ringColor: [{
          offset: 0,
          color: '#06d3f8' // 0% 处的颜色
        }, {
          offset: 1,
          color: '#c1f632' // 100% 处的颜色
        }]
      }
      myChart.setOption({
          title: {
            text: datas.value + datas.company,
            x: 'center',
            y: 'center',
            textStyle: {
              fontWeight: 'normal',
              color: '#2bfaff',
              fontSize: '.50rem'
            }
          },
          color: ['#008def'],
          legend: {
            show: false,
            data: []
          },

          series: [{
            name: 'Line 1',
            type: 'pie',
            clockWise: true,
            radius: ['70%', '80%'],
            itemStyle: {
              normal: {
                label: {
                  show: false
                },
                labelLine: {
                  show: false
                }
              }
            },
            hoverAnimation: false,
            data: [{
              value: datas.value,
              name: '',
              itemStyle: {
                normal: {
                  color: { // 完成的圆环的颜色
                    colorStops: datas.ringColor
                  },
                  label: {
                    show: false
                  },
                  labelLine: {
                    show: false
                  }
                }
              }
            }, {
              name: '',
              value: 100 - datas.value
            }]
          }]
      });
    }
  },
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值