Vue项目如何引入echarts

一、安装 echarts

npm install echarts -S

二、main.js 中全局引入 echarts

// 引入 echarts
import * as echarts from 'echarts'
Vue.prototype.$echarts = echarts

三、使用

<template>
  <div class="column-container">
    <div ref="monthWorkOrder" class="echarts-box" style="width: 600px; height: 300px; border: 1px solid red"></div>
  </div>
</template>

<script>
export default {
  name: 'Column',
  data() {
    return {}
  },
  mounted() {
    this.initMonthWorkOrder()
  },
  methods: {
    // 月工单处理数
    initMonthWorkOrder() {
      let myChart = this.$echarts.init(this.$refs.monthWorkOrder)
      let options = {
        tooltip: {
          backgroundColor: 'rgba(204, 221, 255, 0.6)',
          trigger: 'axis',
          borderColor: '#CCDDFF',
          textStyle: { color: '#2562DC' }
        },
        color: ['#635df7', '#f15d5d'],
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },
        xAxis: [
          {
            type: 'category',
            data: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],
            axisTick: {
              alignWithLabel: true
            }
          }
        ],
        yAxis: [
          {
            type: 'value',
            splitLine: {
              show: true,
              lineStyle: {
                type: 'dashed',
                color: '#D3D8DD'
              }
            }
          }
        ],
        series: [
          {
            name: '维修',
            type: 'bar',
            barWidth: 10,
            data: [141, 39, 10, 16, 79, 116, 67, 104, 12, 36, 20, 128]
          },
          {
            name: '保养',
            type: 'bar',
            barWidth: 10,
            data: [36, 124, 112, 87, 16, 28, 80, 24, 112, 146, 127, 105]
          }
        ]
      }
      myChart.setOption(options)
    }
  }
}
</script>

<style lang="scss" scoped>
.column-container {
  height: 100%;
}
</style>

效果图如下:
在这里插入图片描述
注意:echarts盒子一定要给宽高

  • 7
    点赞
  • 28
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值