vue集成echart(柱状图)

匿名 (未验证) 提交于 2019-12-03 00:17:01
cnpm install echarts -S// 引入echarts import echarts from 'echarts' Vue.prototype.$echarts = echarts ---------------------------------------------------<template>     <div id="myChart" :style="{width: '1300px', height: '600px'}"></div> </template>  <script>     export default {         name: 'FilmChart',         data () {             return {                 msg: 'Welcome to Your Vue.js App',                 xData: ['11','22','33'],                 yData: [2,3,4]             }         },         mounted(){             this.getX();             this.getY();             this.drawLine();         },         methods: {              drawLine(){                                   // 基于准备好的dom,初始化echarts实例                 let myChart = this.$echarts.init(document.getElementById('myChart'))                 // 绘制图表                  myChart.setOption({                     title: { text: '影片统计' },                     tooltip: {},                     xAxis: {                         data: this.xData                     },                     yAxis: {},                     series: [{                         name: '数量',                         type: 'bar',                         data: this.yData                     }]                 });             },             async getX(){   /*同步请求,异步可能出问题,方法调用时数据还没完成替换*/                 var res =  await this.axios.get("type/typeList1")                      for (let i=0;i<res.data.length;i++){                         this.xData[i] = res.data[i].typeName                     }                     console.log(this.xData)               },             async getY(){                 var res =  await this.axios.get("film/countFilm")                     for (let i=0;i<res.data.length;i++){                         this.yData[i] = res.data[i]                     }                     console.log(this.yData)                      this.drawLine();              },         },         watch:{             'xData':function(){                  console.log('watch_xData:'+this.xData);             }         }     } </script>  <style scoped>  </style>

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!