在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. Spring @Primary和@Qualifier注解原理解析2. 詳解php如何合并身份證正反面圖片為一張圖片3. 如何用python識(shí)別滑塊驗(yàn)證碼中的缺口4. php設(shè)計(jì)模式之模板模式實(shí)例分析【星際爭(zhēng)霸游戲案例】5. AJAX實(shí)現(xiàn)省市縣三級(jí)聯(lián)動(dòng)效果6. ASP.NET MVC視圖頁(yè)使用jQuery傳遞異步數(shù)據(jù)的幾種方式詳解7. Java基于redis和mysql實(shí)現(xiàn)簡(jiǎn)單的秒殺(附demo)8. SpringBoot+SpringCache實(shí)現(xiàn)兩級(jí)緩存(Redis+Caffeine)9. HTML iframe標(biāo)簽用法案例詳解10. ASP.NET 2.0頁(yè)面框架的幾處變化
