Vue使用echarts可視化組件的方法
echarts組件官網(wǎng)地址:https://echarts.apache.org/examples/zh/index.html
1.找到腳手架項(xiàng)目所在地址,執(zhí)行cnpm install echarts,安裝echarts組件(腳手架的地址就是你vue項(xiàng)目的地址)
(E:demovuepro)這是我的項(xiàng)目地址,vuepro為項(xiàng)目名
2.按需導(dǎo)入,以加快打開(kāi)速度
//引入echarts組件 import echarts from 'echarts' // 引入基本模板 let echart = require(’echarts/lib/echarts’) // 引入柱狀圖組件 require(’echarts/lib/chart/bar’) // 引入提示框和title組件 require(’echarts/lib/component/tooltip’) require(’echarts/lib/component/title’)
3.準(zhǔn)備div標(biāo)簽 容納報(bào)表圖形
div的 id用于綁定echarts插件
<div style='width: 50%; height: 400px;'> </div>
4.script標(biāo)簽的內(nèi)容
//引入echarts組件 import echarts from 'echarts' // 引入基本模板 let echart = require(’echarts/lib/echarts’) // 引入柱狀圖組件 require(’echarts/lib/chart/bar’) // 引入提示框和title組件 require(’echarts/lib/component/tooltip’) require(’echarts/lib/component/title’) export default{name: ’App’,data(){ return{ chartColumn:null }},methods:{ initData(){ let dt=document.querySelector('#boss') this.chartColumn=echart.init(dt) this.chartColumn.setOption( //Examples中的模板 ) }},mounted(){ this.initData()} }
為了方便大家的使用,我在這里放一個(gè)在Vue中引入echarts可視化組件的完整模板,大家直接復(fù)制使用即可
<template> <div style='width: 500px;height: 500px;'> </div></template><script> //引入echarts組件 import echarts from 'echarts' // 引入基本模板 let echart = require(’echarts/lib/echarts’) // 引入柱狀圖組件 require(’echarts/lib/chart/bar’) // 引入提示框和title組件 require(’echarts/lib/component/tooltip’) require(’echarts/lib/component/title’) export default{name: ’App’,data(){ return{ chartColumn:null }},methods:{ initData(){ let dt=document.querySelector('#boss')this.chartColumn=echart.init(dt) this.chartColumn.setOption( //Examples中模板 ) }},mounted(){ this.initData()} }</script><style></style>
案例:
<template> <div style='width: 500px;height: 500px;'> </div></template><script> import echarts from 'echarts' // 引入基本模板 let echart = require(’echarts/lib/echarts’) // 引入柱狀圖組件 require(’echarts/lib/chart/bar’) // 引入提示框和title組件 require(’echarts/lib/component/tooltip’) require(’echarts/lib/component/title’) export default{name: ’App’,data(){ return{ chartColumn:null }},methods:{ initData(){ let dt=document.querySelector('#boss') this.chartColumn=echart.init(dt) this.chartColumn.setOption( //以下為echarts可視化組件 { tooltip: { trigger: ’axis’, axisPointer: { // Use axis to trigger tooltip type: ’shadow’// ’shadow’ as default; can also be ’line’ or ’shadow’ } }, legend: { data: [’Direct’, ’Mail Ad’, ’Affiliate Ad’, ’Video Ad’, ’Search Engine’] }, grid: { left: ’3%’, right: ’4%’, bottom: ’3%’, containLabel: true }, xAxis: { type: ’value’ }, yAxis: { type: ’category’, data: [’Mon’, ’Tue’, ’Wed’, ’Thu’, ’Fri’, ’Sat’, ’Sun’] }, series: [ { name: ’Direct’, type: ’bar’, stack: ’total’, label: { show: true }, emphasis: { focus: ’series’ }, data: [320, 302, 301, 334, 390, 330, 320] }, { name: ’Mail Ad’, type: ’bar’, stack: ’total’, label: { show: true }, emphasis: { focus: ’series’ }, data: [120, 132, 101, 134, 90, 230, 210] }, { name: ’Affiliate Ad’, type: ’bar’, stack: ’total’, label: { show: true }, emphasis: { focus: ’series’ }, data: [220, 182, 191, 234, 290, 330, 310] }, { name: ’Video Ad’, type: ’bar’, stack: ’total’, label: { show: true }, emphasis: { focus: ’series’ }, data: [150, 212, 201, 154, 190, 330, 410] }, { name: ’Search Engine’, type: ’bar’, stack: ’total’, label: { show: true }, emphasis: { focus: ’series’ }, data: [820, 832, 901, 934, 1290, 1330, 1320] } ] } //組件到此結(jié)束 ) }},mounted(){ this.initData()} }</script><style></style>
顯示效果:
到此這篇關(guān)于Vue使用echarts可視化組件的方法的文章就介紹到這了,更多相關(guān)Vue echarts可視化組件內(nèi)容請(qǐng)搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!
相關(guān)文章:
1. XML入門(mén)的常見(jiàn)問(wèn)題(三)2. .NET Core 分布式任務(wù)調(diào)度ScheduleMaster詳解3. 不要在HTML中濫用div4. HTML5實(shí)戰(zhàn)與剖析之觸摸事件(touchstart、touchmove和touchend)5. CSS清除浮動(dòng)方法匯總6. HTTP協(xié)議常用的請(qǐng)求頭和響應(yīng)頭響應(yīng)詳解說(shuō)明(學(xué)習(xí))7. XML在語(yǔ)音合成中的應(yīng)用8. ASP將數(shù)字轉(zhuǎn)中文數(shù)字(大寫(xiě)金額)的函數(shù)9. XML 非法字符(轉(zhuǎn)義字符)10. jscript與vbscript 操作XML元素屬性的代碼
