vue-cli 引入echarts

1、 安装依赖 cnpm install echarts -S

全局引入

在main.js中

// 引入echarts
import echarts from 'echarts'

Vue.prototype.$echarts = echarts 

局部引入

在用到的vue文件中

<script>
// 引入基本模板
let echarts = require('echarts/lib/echarts')
// 引入柱状图组件
require("echarts/lib/chart/line")
// 引入提示框和title组件
require('echarts/lib/component/tooltip')
require('echarts/lib/component/title')

export default {
  data () {
    return {
        
    }
  },//end data()

  mounted(){
    this.getDbData();
    // this.drawLine();
  },

  methods: {
    resizeCharts (echartsDom,chartBox) {
      echartsDom.style.width = window.innerWidth+'px';
      echartsDom.style.height = (window.innerHeight-100)+'px';
    },
    getDbData(){
      const $this =this;

      this.$http.get('/warn/api/dashbord')
        .then(res => {
          $this.drawLine(res.data);
        })
        .catch(err => {

        })
    },
    drawLine(dbData){
      let chartBox = document.getElementsByClassName('charts')[0]
      let echartsDom = document.getElementById('echarts')

      this.resizeCharts(echartsDom,chartBox);
      // 基于准备好的dom,初始化echarts实例
      let myChart = echarts.init(echartsDom); //若是全局引入,这里使用this.$echarts.init(echartsDom)
      // 绘制图表
      myChart.setOption({
          title: {
             left: 'left',
             text: '监控预警统计'
            },
          tooltip: {},
          xAxis: {
              data: dbData.data.Doing.date
          },
          yAxis: {},
          series: [{
              name: '预警提示',
              type: 'line',
              data: dbData.data.Doing.value
          },{
            name: '预警待办',
            type: 'line',
            data: dbData.data.Reading.value
          }]
      });
    }
  }//end methods
};
</script>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值