代码:
(先安装echarts,在main.js中引入并注册进prototype)
import Vue from 'vue'
import App from './App.vue'
import router from './router'
import './plugins/element.js'
import * as echarts from 'echarts'
Vue.config.productionTip = false
Vue.prototype.$echarts = echarts
new Vue({
router,
render: h => h(App)
}).$mount('#app')
使用:
<template>
<div>
<el-card shadow="always">
123
<div id="xuanwo">
</div>
</el-card>
</div>
</template>
<script>
export default {
name: 'TopView',
components: {
},
mounted(){
const chartDom = document.getElementById('xuanwo');
const chart = this.$echarts.init(chartDom);
chart.setOption({
xAxis:{
type:'category',
show:false,
boundaryGap:false
},
yAxis:{
show:false,
},
series:[{
type:'line',
data:[620,432,220,534,790,430,220,320,532,320,834,690,530,220,628],
areaStyle:{
color:'purple'
},
lineStyle:{
width:0
},
itemStyle:{
width:0,
opacity:0
},
smooth:true
}],
grid:{
top:0,
bottom:0,
left:0,
right:0
}
})
}
}
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="scss">
#xuanwo{
width: 300px;
height: 300px;
}
</style>