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:\demo\vuepro)這是我的項(xiàng)目地址,vuepro為項(xiàng)目名
2.按需導(dǎo)入,以加快打開速度
//引入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 id="chart" 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 id="boss" 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 id="boss" 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)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- 詳解Vue2+Echarts實(shí)現(xiàn)多種圖表數(shù)據(jù)可視化Dashboard(附源碼)
- Vue使用Echarts實(shí)現(xiàn)數(shù)據(jù)可視化的方法詳解
- 基于vue+echarts數(shù)據(jù)可視化大屏展示的實(shí)現(xiàn)
- vue中的echarts實(shí)現(xiàn)寬度自適應(yīng)的解決方案
- Vuejs通過拖動改變元素寬度實(shí)現(xiàn)自適應(yīng)
- Vue實(shí)現(xiàn)input寬度隨文字長度自適應(yīng)操作
- Vue中使用Echarts可視化圖表寬度自適應(yīng)的完美解決方案
相關(guān)文章
vue.js?自定義指令(拖拽、拖動、移動)?指令?v-drag詳解
這篇文章主要介紹了vue.js?自定義指令(拖拽、拖動、移動)?指令?v-drag,本文結(jié)合示例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2023-01-01vue3 ElementUI 日期禁選當(dāng)日前當(dāng)日后三天后的實(shí)現(xiàn)代碼
這篇文章主要介紹了vue3 ElementUI 日期禁選當(dāng)日前當(dāng)日后三天后的實(shí)現(xiàn)代碼,本文通過示例代碼給大家介紹的非常詳細(xì),感興趣的朋友跟隨小編一起看看吧2024-05-05Vue3使用富文本框(wangeditor)的方法總結(jié)
項(xiàng)目中用到了富文本,選來選去選擇了wangeditor,下面這篇文章主要給大家介紹了關(guān)于Vue3使用富文本框(wangeditor)的相關(guān)資料,文中通過代碼介紹的非常詳細(xì),需要的朋友可以參考下2024-01-01vue cli3.x打包后如何修改生成的靜態(tài)資源的目錄和路徑
這篇文章主要介紹了vue cli3.x打包后如何修改生成的靜態(tài)資源的目錄和路徑,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-04-04vue路由導(dǎo)航守衛(wèi)和請求攔截以及基于node的token認(rèn)證的方法
這篇文章主要介紹了vue路由導(dǎo)航守衛(wèi)和請求攔截以及基于node的token認(rèn)證的方法,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2019-04-04vue 父組件給子組件傳值子組件給父組件傳值的實(shí)例代碼
這篇文章主要介紹了vue 父組件給子組件傳值,子組件給父組件傳值,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-04-04