当前位置:   article > 正文

Vue项目如何引入echarts_vue项目引入echarts

vue项目引入echarts

一、安装 echarts

npm install echarts -S

二、main.js 中全局引入 echarts

// 引入 echarts
import * as echarts from 'echarts'
Vue.prototype.$echarts = echarts
  • 1
  • 2
  • 3

三、使用

<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>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80

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

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家自动化/article/detail/769391
推荐阅读
相关标签