Vue With Echarts 1

最近專業(yè)拓展一直在學(xué)vue,但是一開始就直接進(jìn)入vue與echarts的使用,基礎(chǔ)都還沒有搭好,哎.....感嘆一下與同學(xué)們的差距

先來記錄以下vue中echarts的引用

1.要先安裝echarts? >npm install echarts --save

2.在views文件夾里創(chuàng)建.vue文件 在文件里面進(jìn)行echarts的引用

文件安排

3.各個(gè)js文件中的引入

在main.js中添加import echartsfrom 'echarts'? ? ?Vue.prototype.$echarts = echarts

在index.js中添加? ? import echart1from '../views/echart1'

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?import echart2from '../views/echart2'

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?import echart3from '../views/echart3'

component和path引入

在app.vue中添加?

app.vue

4.接下來可以開始寫正文了

<template>

<div id="myChart1" :style="{position:'absolute',width:'500px',height:'380px',backgroundColor:'',top:'50px'}"></div>

</template>

<script>

export default {

name:'echart1',

data () {

return {}

},

mounted () {

this.drawLine()

},

methods: {

drawLine () {

// 基于準(zhǔn)備好的dom,初始化echarts實(shí)例

? ? ? const myChart1 =this.$echarts.init(document.getElementById('myChart1'))

// 繪制圖表? 從echarts官網(wǎng)中選取自己想要的圖表 然后將代碼拷貝到setOption中就可以啦

? ? ? myChart1.setOption({?

tooltip: {

? ? trigger:'item',

? ? formatter:'{a} <br/> : {c} (u0z1t8os%)'

},

legend: {

data: ['郵件營銷','聯(lián)盟廣告','視頻廣告','直接訪問','搜索引擎'],

top:'5%',

left:'5%',

orient:'vertical',

textStyle:{

color:'black',

}

},

toolbox: {

feature: {

saveAsImage: {}

}

},

visualMap: {

show:false,

min:80,

max:600,

inRange: {

colorLightness: [0,1]

}

},

series: [

{

name:'訪問來源',

type:'pie',

radius:'55%',

center: ['58%','50%'],

data: [

{

value:335,

name:'直接訪問'

? ? ? ? ? ? ? },

{

value:310,

name:'郵件營銷'

? ? ? ? ? ? ? },

{

value:274,

name:'聯(lián)盟廣告'

? ? ? ? ? ? ? },

{

value:235,

name:'視頻廣告'

? ? ? ? ? ? ? },

{

value:400,

name:'搜索引擎'

? ? ? ? ? ? ? }

].sort(function (a, b) {

return a.value - b.value;

}),

roseType:'radius',

label: {

color:'black'

? ? ? ? ? ? },

labelLine: {

lineStyle: {

color:'black'

? ? ? ? ? ? ? },

smooth:0.2,

length:10,

length2:20

? ? ? ? ? ? },

itemStyle: {

color:'#b5838d',

},

animationType:'scale',

animationEasing:'elasticOut',

animationDelay:function (idx) {

return Math.random() *200

? ? ? ? ? ? }

}

]

})

}

}

}

</script>

<style lang="less" scoped>

</style>

5.看下效果圖嘿嘿


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

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

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