vue中使用echarts

1、簡介

echarts是一個數(shù)據(jù)可視化工具,是我們數(shù)據(jù)不再只是單單的展示出來,而可以使其通過圖標(biāo)的方式形象的展示,那么如何再vue中引用呢?

2、安裝

通過如下命令進行安裝echarts。

npm install echarts --save

3、配置

在main.js中進行如下配置:

import Vue from 'vue'
import App from './App.vue'
import * as echarts from 'echarts'

Vue.prototype.$echarts = echarts

Vue.config.productionTip = false

new Vue({
  render: h => h(App),
}).$mount('#app')

4、使用

  • template代碼如下:
<template>
  <div id="app">
      <div id='wrap' style=''></div>
  </div>
</template>
  • script代碼如下
<script>
export default {
  name: 'App',
  mounted() {
      this.myCharts()
  },
  methods: {
      myCharts() {
          let myCharts = this.$echarts.init(document.getElementById('wrap'))
          let option = {
                xAxis: {
                    type: 'category',
                    data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
                },
                yAxis: {
                    type: 'value'
                },
                series: [{
                    data: [120, 200, 150, 80, 70, 110, 130],
                    type: 'bar',
                    showBackground: true,
                    backgroundStyle: {
                        color: 'rgba(180, 180, 180, 0.2)'
                    }
                }]
            };
          myCharts.setOption(option)
      }
  }
}
</script>
  • style代碼如下:
<style>
    #wrap{
        height: 400px;
        background-color: #ffs;
        width: 300px
    }
</style>
  • 效果如下圖所示:


    在vue中使用echarts效果圖
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容