echarts在vue中的使用
1.使用npm安装依赖包
npm install echarts -S
或者使用淘宝的镜像
npm install -g cnpm —registry=https://registry.npm.taobao.org
cnpm install echarts -S
2.在main.js中全局引入
// 引入echarts
import echarts from 'echarts'
Vue.prototype.$echarts = echarts
3.在vue中使用
<template>
<div>
<div id="myChart" :style="{width: '300px', height: '300px'}"></div>
</div>
</template>
<script lang="ts">
import {
Component,
Vue,
Watch
} from 'vue-property-decorator';
import {
Action,
State
} from 'vuex-class'
import fa from "element-ui/src/locale/lang/fa";
import {getCrowds,addBatch,getGivingCoupons} from '@/common/fetch'
@Component({
mixins:[],
components: {
}
})
export default class AddProduct extends Vue {
show(){
// 基于准备好的dom,初始化echarts实例
let myChart = this.$echarts.init(document.getElementById('myChart'))
// 绘制图表
myChart.setOption({
color:['#9AC0F3'],
xAxis: {
type: 'category',
data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
},
yAxis: {
type: 'value'
},
series: [{
data: [820, 932, 901, 934, 1290, 1330, 1320],
type: 'line',
itemStyle : { normal: {label : {show: true}}},
smooth: true
}]
});
}
mounted(){
this.show()
}
}
</script>
<style scoped>
</style>
还没有评论,来说两句吧...