在Vue中使用Echarts實例圖的方法實例
前言
由于在項目中需要對數(shù)據(jù)進行可視化處理,也就是用圖表展示,眾所周知echarts是非常強大的插件。但是新手猛的上手的話,可能會有點束手無策,所以這篇就是來寫一點入門的內(nèi)容,外加自己一點的小心得。
一、首先要在項目中下載echarts依賴
npm install echarts -S //或者使用淘寶的鏡像 cnpm install echarts -S
二、然后就要再main.js文件中來進行全局引入
// 引入echarts import echarts from 'echarts' Vue.prototype.$echarts = echarts
三、在Vue組件中設置一個div
<template> <div> <div class="body"> <div id="echarts"></div> //就是這一行 </div> </div> </template>
四、去Echarts官網(wǎng)尋找想設置的實例圖
再然后,根據(jù)找到的這個圖里的數(shù)據(jù)及變量,來進行聲明到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"));
//設置echarts對象的option屬性
myChart.setOption(this.option)
}
六、再在該div外面的盒子設置相關(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)文章
淺析Visual Studio Code斷點調(diào)試Vue
本篇文章給大家總結(jié)了Visual Studio Code斷點調(diào)試Vue的方法以及心得分享,需要的朋友參考學習下。2018-02-02
Vite處理html模板插件之vite-plugin-html插件使用
這篇文章主要給大家介紹了關(guān)于Vite處理html模板插件之vite-plugin-html插件使用的相關(guān)資料,Vite是一個現(xiàn)代化的前端構(gòu)建工具,而vite-plugin-html是Vite的一個插件,用于在構(gòu)建時自動生成HTML文件,需要的朋友可以參考下2023-10-10
使用Vue+Django+Ant Design做一個留言評論模塊的示例代碼
這篇文章主要介紹了使用Vue+Django+Ant Design做一個留言評論模塊,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2020-06-06

