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,175評論 0 1
  • Vue2.0+組件庫總結 UI組件 element - 餓了么出品的Vue2的web UI工具套件 Vux - 基...
    szch閱讀 1,981評論 1 52
  • UI組件 element- 餓了么出品的Vue2的web UI工具套件 Vux- 基于Vue和WeUI的組件庫 m...
    小姜先森o0O閱讀 9,614評論 0 72
  • UI組件 element- 餓了么出品的Vue2的web UI工具套件 Vux- 基于Vue和WeUI的組件庫 m...
    35eeabfa0772閱讀 3,287評論 7 12
  • UI組件 element- 餓了么出品的Vue2的web UI工具套件 Vux- 基于Vue和WeUI的組件庫 m...
    柴東啊閱讀 15,876評論 2 140