在Vue中使用Echarts實(shí)例圖的方法實(shí)例
前言
由于在項(xiàng)目中需要對(duì)數(shù)據(jù)進(jìn)行可視化處理,也就是用圖表展示,眾所周知echarts是非常強(qiáng)大的插件。但是新手猛的上手的話,可能會(huì)有點(diǎn)束手無(wú)策,所以這篇就是來(lái)寫(xiě)一點(diǎn)入門(mén)的內(nèi)容,外加自己一點(diǎn)的小心得。
一、首先要在項(xiàng)目中下載echarts依賴(lài)
npm install echarts -S //或者使用淘寶的鏡像 cnpm install echarts -S
二、然后就要再main.js文件中來(lái)進(jìn)行全局引入
// 引入echarts import echarts from 'echarts' Vue.prototype.$echarts = echarts
三、在Vue組件中設(shè)置一個(gè)div
<template> <div> <div class="body"> <div id="echarts"></div> //就是這一行 </div> </div> </template>
四、去Echarts官網(wǎng)尋找想設(shè)置的實(shí)例圖
再然后,根據(jù)找到的這個(gè)圖里的數(shù)據(jù)及變量,來(lái)進(jìn)行聲明到data中。
data() {
return {
option: {
title: {
text: '堆疊區(qū)域圖'
},
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'cross',
label: {
backgroundColor: '#6a7985'
}
}
},
legend: {
data: ['郵件營(yíng)銷(xiāo)', '聯(lián)盟廣告', '視頻廣告', '直接訪問(wèn)', '搜索引擎']
},
grid: {
left: '3%',
right: '4%',
bottom: '3%',
containLabel: true
},
xAxis: [{
type: 'category',
boundaryGap: false,
data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
}],
yAxis: [{
type: 'value'
}],
series: [{
name: '郵件營(yíng)銷(xiāo)',
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: '直接訪問(wèn)',
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對(duì)象的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>
好啦,這個(gè)時(shí)候自信一點(diǎn),打開(kāi)瀏覽器,就會(huì)發(fā)現(xiàn)一個(gè)完完全全的Echarts實(shí)例圖啦,希望這篇文章可以幫得到你,嘻嘻
總結(jié)
到此這篇關(guān)于在Vue中使用Echarts實(shí)例圖的文章就介紹到這了,更多相關(guān)Vue使用Echarts實(shí)例圖內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
淺析Visual Studio Code斷點(diǎn)調(diào)試Vue
本篇文章給大家總結(jié)了Visual Studio Code斷點(diǎn)調(diào)試Vue的方法以及心得分享,需要的朋友參考學(xué)習(xí)下。2018-02-02
Vite處理html模板插件之vite-plugin-html插件使用
這篇文章主要給大家介紹了關(guān)于Vite處理html模板插件之vite-plugin-html插件使用的相關(guān)資料,Vite是一個(gè)現(xiàn)代化的前端構(gòu)建工具,而vite-plugin-html是Vite的一個(gè)插件,用于在構(gòu)建時(shí)自動(dòng)生成HTML文件,需要的朋友可以參考下2023-10-10
使用Vue+Django+Ant Design做一個(gè)留言評(píng)論模塊的示例代碼
這篇文章主要介紹了使用Vue+Django+Ant Design做一個(gè)留言評(píng)論模塊,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-06-06
form?表單驗(yàn)證是異步問(wèn)題記錄(推薦)
這篇文章主要介紹了form?表單驗(yàn)證是異步問(wèn)題記錄,通過(guò)實(shí)例代碼介紹了Promise.all 和 Promise.allSettled 區(qū)別,需要的朋友可以參考下2023-01-01

