Vuejs使用Echarts

在VueJS当中使用Echarts

安装Echars

npm install Echarts --save

vuejs当中的main.js文件

// 引入echars
import echarts from 'echarts'
// 添加echarts插件
Vue.prototype.$echarts = echarts

prototype 属性使您有能力向对象添加属性和方法。

vuejs当中的hello.vue(cli创建就有这个文件哦)

其实这里hello.vue指代的是组件,你可以使用任意组件。

<template>
  <div class="hello">
    <div id="myChart" :style="{width: '100%', height: '400px'}"></div>
  </div>
</template>

<script>
export default {
  name: 'hello',
  data () {
    return {
      xVipData: [],
      yVipData: []
    }
  },
  mounted () {
    this.$http.get('http://www.xxxx.com/api/v1/data/vip/increment').then(response => {
      this.xVipData = response.body.xVipData
      this.yVipData = response.body.yVipData
      this.drawLine()
    }, response => {
      console.log('数据请求失败')
    })
  },
  methods: {
    drawLine () {
      // 基于准备好的dom,初始化echarts实例
      let myChart = this.$echarts.init(document.getElementById('myChart'))
      // 绘制图表
      myChart.setOption({
        title: {
          text: '每月会员增长折线图',
          left: 'center'
        },
        tooltip: {},
        xAxis: {
          data: this.xVipData
        },
        yAxis: {},
        series: [{
          name: '每月会员增长曲线折线图',
          type: 'line',
          data: this.yVipData
        }]
      })
    }
  }
}
</script>

效果

效果
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 基于Vue的一些资料 内容 UI组件 开发框架 实用库 服务端 辅助工具 应用实例 Demo示例 element★...
    尝了又尝阅读 1,187评论 0 1
  • Vue2.0+组件库总结 UI组件 element - 饿了么出品的Vue2的web UI工具套件 Vux - 基...
    szch阅读 1,985评论 1 52
  • UI组件 element- 饿了么出品的Vue2的web UI工具套件 Vux- 基于Vue和WeUI的组件库 m...
    小姜先森o0O阅读 9,668评论 0 72
  • UI组件 element- 饿了么出品的Vue2的web UI工具套件 Vux- 基于Vue和WeUI的组件库 m...
    35eeabfa0772阅读 3,298评论 7 12
  • UI组件 element- 饿了么出品的Vue2的web UI工具套件 Vux- 基于Vue和WeUI的组件库 m...
    柴东啊阅读 15,878评论 2 140