在Vue中使用Echarts實(shí)例圖的方法實(shí)例
前言
由于在項(xiàng)目中需要對(duì)數(shù)據(jù)進(jìn)行可視化處理,也就是用圖表展示,眾所周知echarts是非常強(qiáng)大的插件。但是新手猛的上手的話,可能會(huì)有點(diǎn)束手無策,所以這篇就是來寫一點(diǎn)入門的內(nèi)容,外加自己一點(diǎn)的小心得。
一、首先要在項(xiàng)目中下載echarts依賴
npm install echarts -S//或者使用淘寶的鏡像cnpm install echarts -S
二、然后就要再main.js文件中來進(jìn)行全局引入
// 引入echartsimport 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ù)及變量,來進(jìn)行聲明到data中。
data() {return {option: {title: {text: ’堆疊區(qū)域圖’},tooltip: {trigger: ’axis’,axisPointer: {type: ’cross’,label: {backgroundColor: ’#6a7985’}}},legend: {data: [’郵件營(yíng)銷’, ’聯(lián)盟廣告’, ’視頻廣告’, ’直接訪問’, ’搜索引擎’]},grid: {left: ’3%’,right: ’4%’,bottom: ’3%’,containLabel: true},xAxis: [{type: ’category’,boundaryGap: false,data: [’周一’, ’周二’, ’周三’, ’周四’, ’周五’, ’周六’, ’周日’]}],yAxis: [{type: ’value’}],series: [{name: ’郵件營(yíng)銷’,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對(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),打開瀏覽器,就會(huì)發(fā)現(xiàn)一個(gè)完完全全的Echarts實(shí)例圖啦,希望這篇文章可以幫得到你,嘻嘻
總結(jié)
到此這篇關(guān)于在Vue中使用Echarts實(shí)例圖的文章就介紹到這了,更多相關(guān)Vue使用Echarts實(shí)例圖內(nèi)容請(qǐng)搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!
相關(guān)文章:
1. IDEA巧用Postfix Completion讓碼速起飛(小技巧)2. Python如何批量獲取文件夾的大小并保存3. docker /var/lib/docker/aufs/mnt 目錄清理方法4. CSS代碼檢查工具stylelint的使用方法詳解5. Python中Selenium模塊的使用詳解6. Python的Tqdm模塊實(shí)現(xiàn)進(jìn)度條配置7. Python 多線程之threading 模塊的使用8. CSS3中Transition屬性詳解以及示例分享9. IntelliJ IDEA2020.2.2創(chuàng)建Servlet方法及404問題10. Python基于smtplib模塊發(fā)送郵件代碼實(shí)例
