vue.js运用echarts一分钟简朴入门

图表的运用在企业级软件中运用愈来愈广泛,前端开辟人员能够运用经常使用的echarts开源库来举行图表展现的开辟,公司近来提出须要雄厚体系首页的内容,趁此机会分享一下如安在运用vue.js框架下运用echarts.

1,肯定你须要引入的echarts版本,官网地点:http://echarts.baidu.com/inde…
2,npm或许cnpm装置

 cnpm install echarts --save

3,按需引入。这里我强烈推荐按需引入,echarts图范例浩瀚,我们平常不须要将每一个图表都引入,如许也有利于削减打包体积,这里我发起将每一个echarts图封装成一个组件。
重要代码以下

<el-col :span='24'>
    <v-charts></v-charts>
 </el-col>

4组件部份源码

<template>
  <div class="line">
      <div class="main" ref="main">         
      </div>
    </div> 
</template>
<script>
let echarts = require('echarts/lib/echarts');//引入echarts
require('echarts/lib/chart/bar'); //引入柱状图
// 引入提示框和题目组件
require('echarts/lib/component/tooltip');
require('echarts/lib/component/title');

export default{
   data(){
     return{
      myChart:{}
     }
   },
   mounted(){
    this.initEcharts();
   },
   methods:{
    initEcharts(){
      let THIS=this;
      let mainDiv = THIS.$refs.main; //找到绘制的地区,强烈推荐运用refs
      var myChart = echarts.init(mainDiv); //初始化
      myChart.setOption({ //官网例子
        title: {
            text: 'ECharts 入门示例'
        },
        tooltip: {},
        xAxis: {
            data: ['衬衫', '羊毛衫', '雪纺衫', '裤子', '高跟鞋', '袜子']
        },
        yAxis: {},
        series: [{
            name: '销量',
            type: 'bar',
            data: [5, 20, 36, 10, 10, 20]
        }]
     });
    }
   }
}    
</script>
<style lang='stylus' scoped>
.line
  height 100%
  .main
    width:300px; //宽高也不可少
    height:200px;  
</style>

4完成结果以下

《vue.js运用echarts一分钟简朴入门》

5,按需引入其他图表,能够参考能够按需引入的模块列表见 https://github.com/ecomfe/ech…

    原文作者:黎明破晓的街道
    原文地址: https://segmentfault.com/a/1190000015894677
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞