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效果圖
