在Vue中使用Echarts實例圖的方法實例
前言
由于在項目中需要對數(shù)據(jù)進(jìn)行可視化處理,也就是用圖表展示,眾所周知echarts是非常強大的插件。但是新手猛的上手的話,可能會有點束手無策,所以這篇就是來寫一點入門的內(nèi)容,外加自己一點的小心得。
一、首先要在項目中下載echarts依賴
npm install echarts -S //或者使用淘寶的鏡像 cnpm install echarts -S
二、然后就要再main.js文件中來進(jìn)行全局引入
// 引入echarts import echarts from 'echarts' Vue.prototype.$echarts = echarts
三、在Vue組件中設(shè)置一個div
<template> <div> <div class="body"> <div id="echarts"></div> //就是這一行 </div> </div> </template>
四、去Echarts官網(wǎng)尋找想設(shè)置的實例圖
再然后,根據(jù)找到的這個圖里的數(shù)據(jù)及變量,來進(jìn)行聲明到data中。
data() {
return {
option: {
title: {
text: '堆疊區(qū)域圖'
},
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'cross',
label: {
backgroundColor: '#6a7985'
}
}
},
legend: {
data: ['郵件營銷', '聯(lián)盟廣告', '視頻廣告', '直接訪問', '搜索引擎']
},
grid: {
left: '3%',
right: '4%',
bottom: '3%',
containLabel: true
},
xAxis: [{
type: 'category',
boundaryGap: false,
data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
}],
yAxis: [{
type: 'value'
}],
series: [{
name: '郵件營銷',
type: 'line',
stack: '總量',
areaStyle: {},
data: [120, 132, 101, 134, 90, 230, 210]
},
{
name: '聯(lián)盟廣告',
type: 'line',
stack: '總量',
areaStyle: {},
data: [220, 182, 191, 234, 290, 330, 310]
},
{
name: '視頻廣告',
type: 'line',
stack: '總量',
areaStyle: {},
data: [150, 232, 201, 154, 190, 330, 410]
},
{
name: '直接訪問',
type: 'line',
stack: '總量',
areaStyle: {},
data: [320, 332, 301, 334, 390, 330, 320]
},
{
name: '搜索引擎',
type: 'line',
stack: '總量',
label: {
normal: {
show: true,
position: 'top'
}
},
areaStyle: {},
data: [820, 932, 901, 934, 1290, 1330, 1320]
}
]
}
}
}
五、在生命周期中掛載
mounted() {
let myChart = this.$echarts.init(document.getElementById("echarts"));
//設(shè)置echarts對象的option屬性
myChart.setOption(this.option)
}
六、再在該div外面的盒子設(shè)置相關(guān)的css
<style scoped>
.body
{
width: 100%;
height: 100vh;
margin-left: 250px;
margin-top: -280px;
}
#echarts
{
width: 80%;
height: 60%;
border: 1px solid red;
}
</style>
好啦,這個時候自信一點,打開瀏覽器,就會發(fā)現(xiàn)一個完完全全的Echarts實例圖啦,希望這篇文章可以幫得到你,嘻嘻
總結(jié)
到此這篇關(guān)于在Vue中使用Echarts實例圖的文章就介紹到這了,更多相關(guān)Vue使用Echarts實例圖內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Vue2.0實現(xiàn)簡單分頁及跳轉(zhuǎn)效果
這篇文章主要為大家詳細(xì)介紹了Vue2.0實現(xiàn)簡單數(shù)據(jù)分頁,及頁數(shù)的跳轉(zhuǎn)效果,具有一定的參考價值,感興趣的小伙伴們可以參考一下2019-07-07
Vue?ECharts實現(xiàn)機艙座位選擇展示功能代碼詳解
這篇文章主要介紹了Vue?ECharts實現(xiàn)機艙座位選擇展示,本文給大家分享一段簡短的代碼通過效果圖展示給大家介紹的非常明白,需要的朋友可以參考下2022-05-05
vue路由跳轉(zhuǎn)打開新窗口(window.open())和關(guān)閉窗口(window.close())
這篇文章主要介紹了vue路由跳轉(zhuǎn)打開新窗口(window.open())和關(guān)閉窗口(window.close())問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-04-04
vue中beforeRouteLeave實現(xiàn)頁面回退不刷新的示例代碼
這篇文章主要介紹了vue中beforeRouteLeave實現(xiàn)頁面回退不刷新的示例代碼,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-11-11

