Vue2 安装使用echarts

1.npm 安装

npm install echarts --save

2.main.js 引入

import * as echarts from 'echarts'
Vue.prototype.$echarts = echarts;

3.组件使用

import * as echarts from 'echarts';
drawChart() {
  // 基于准备好的dom,初始化echarts实例  这个和上面的main对应
  var myChart = echarts.init(document.getElementById("c2"));
  myChart.setOption({

    backgroundColor: '#031d33',
    grid: {
      top: 0,
      bottom: 0,
      left: '10%',
      right: '10%',
    },
    xAxis: {
      show: false,
      type: 'value',
      boundaryGap: [0, 0],
    },
    yAxis: [
      {
        type: 'category',
        data: [''],
        axisLine: { show: false },
        axisTick: [
          {
            show: false,
          },
        ],
      },
    ],
    series: [
      {
        name: '金额',
        type: 'bar',
        zlevel: 1,
        itemStyle: {
          normal: {
            barBorderRadius: 30,
            color: new echarts.graphic.LinearGradient(1, 0, 0, 1, [
              {
                offset: 1,
                color: 'rgba(48, 236, 166, 1)',
              },
              {
                offset: 0,
                color: 'rgba(48, 236, 166, 0.5)',
              },
            ]),
          },
        },
        barWidth: 20,
        data: [10],
      },
      {
        name: '背景',
        type: 'bar',
        barWidth: 20,
        barGap: '-100%',
        data: [20],
        itemStyle: {
          normal: {
            color: 'rgba(28, 128, 213, 0.19)',
            borderWidth: 1,
            borderColor: 'rgba(48, 236, 166, 1)',
            barBorderRadius: 30,
          },
        },
      },
    ],
  })
},
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值