Vue引入Echarts使用

目录

一、运行环境

二、操作步骤

1.安装echarts

2.引用echarts包

3.局部引用

四、结果展示

五、简单总结


一、运行环境

常用环境:window+vue

二、操作步骤

1.安装echarts

 npm install echarts -S

可能出现错误如下:

出现上图原因可能是npm版本问题报错,可尝试在后面加上 --legacy-peer-deps

 npm install echarts -S --legacy-peer-deps

成功

2.引用echarts包

import * as echarts from 'echarts'

3.局部引用

<template>
  <div :id="id" ref="chart"></div>
</template>

<script>
import * as echarts from 'echarts'

export default {
  name: 'LineChart',
  props: {
    id: {
      type: String,
      default: 'chartBox'
    }
  },
  data () {
    return {
      myChart: null
    }
  },
  methods: {
    initCharts () {
      this.myChart = echarts.init(this.$refs.chart)
      // 绘制图表
      this.myChart.setOption({
        title: { text: '在Vue中使用echarts' },
        tooltip: {},
        xAxis: {
          data: ['衬衫', '羊毛衫', '雪纺衫', '裤子', '高跟鞋', '袜子']
        },
        yAxis: {},
        series: [{
          name: '销量',
          type: 'bar',
          data: [5, 20, 36, 10, 10, 20]
        }]
      })
    }
  },
  mounted () {
    this.initCharts()
  }
}
</script>

<style scoped>

</style>

四、结果展示

五、简单总结

1.简单应用实现,局部引用即可。 

2.注意用   import * as echarts from 'echarts'

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值