Vue?Echarts實(shí)現(xiàn)多功能圖表繪制的示例詳解
前言
作為前端人員,日常圖表、報(bào)表、地圖的接觸可謂相當(dāng)頻繁,今天小編隆重退出前端框架之VUE結(jié)合百度echart實(shí)現(xiàn)中國地圖+各種圖表的展示與使用;作為“你值得擁有”專欄階段性末篇,值得一看
主要實(shí)現(xiàn)功能
- 中國地圖
- 環(huán)形圖
- 折線圖
- 柱形圖
- 復(fù)雜交互
- 單選復(fù)選
環(huán)境搭建
初始化環(huán)境參考:利用vue-cli搭建vue項(xiàng)目框架
項(xiàng)目部署
build project:
npm install
npm run build
npm run dev
訪問地址:
http://localhost:8895/#/dashboard
項(xiàng)目結(jié)構(gòu)

項(xiàng)目代碼
dashboard.vue-主界面
import pie from 'com/pie/pie'
import line from 'com/line/line'
import multipleColumn from 'com/multipleColumn/multipleColumn'
import point from 'com/point/point'
export default {
data() {
return {
items: []
}
},
mounted() {
this.init()
},
methods: {
oresize() {
this.$root.charts.forEach((myChart) => {
myChart.resize()
})
},
init() {
this.items = document.querySelectorAll('.flex-container .item')
for (let i = 0; i < this.items.length; i++) {
this.items[i].dataset.order = i + 1;
}
},
clickChart(clickIndex) {
let activeItem = document.querySelector('.flex-container .active')
let activeIndex = activeItem.dataset.order
let clickItem = this.items[clickIndex - 1]
if (activeIndex === clickIndex) {
return
}
activeItem.classList.remove('active')
clickItem.classList.add('active')
this._setStyle(clickItem, activeItem)
},
_setStyle(el1, el2) {
let transform1 = el1.style.transform
let transform2 = el2.style.transform
el1.style.transform = transform2
el2.style.transform = transform1
}
},
components: {
multipleColumn,
point,
'v-line': line,
pie: pie
}
}multipleColumn.vue-復(fù)合柱形圖
import filter from 'com/filter/filter'
import echarts from 'echarts'
import china from 'echarts/map/js/china'
import world from 'echarts/map/js/world'
import http from 'js/http'
export default {
data() {
return {
mcChart: {},
options2: {
shortcuts: [
{
text: '最近一周',
value () {
const end = new Date();
const start = new Date();
start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
return [start, end];
},
onClick: (picker) => {
}
},
{
text: '最近一個(gè)月',
value () {
const end = new Date();
const start = new Date();
start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
return [start, end];
},
onClick: (picker) => {
}
},
{
text: '最近三個(gè)月',
value () {
const end = new Date();
const start = new Date();
start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
return [start, end];
},
onClick: (picker) => {
}
}
]
},
value2: '',
startTime: '',
endTime: '',
}
},
methods: {
_mcCharts() {
var dom = document.querySelector('.multipleColumn .main')
this.mcChart = echarts.init(dom);
var app = {}, option = null;
app.title = '堆疊柱狀圖';
option = {
title: {
text: '全國主要城市空氣質(zhì)量',
left: 'left',
textStyle: {
color: '#fff',
fontWeight: 300,
}
},
tooltip : {
trigger: 'axis',
axisPointer : { // 坐標(biāo)軸指示器,坐標(biāo)軸觸發(fā)有效
type : 'shadow' // 默認(rèn)為直線,可選為:'line' | 'shadow'
}
},
color: ['#AE5548', '#6D9EA8', '#9CC2B0', '#C98769', '#48cda6','#fd87ab','#11abff','#ffdf33','#968ade'],
legend: {
data:['直接訪問','郵件營銷','聯(lián)盟廣告','視頻廣告','搜索引擎','百度','谷歌','必應(yīng)','其他'],
x: 'right',
textStyle: {
// legend字體顏色
color: '#fff'
}
},
grid: {
left: '5%',
right: '8%',
top: '16%',
bottom: '3%',
containLabel: true
},
xAxis : [
{
name: '時(shí)間',
type : 'category',
data : ['周一','周二','周三','周四','周五','周六','周日'],
axisLine:{
lineStyle:{
color: '#fff',
type:'solid' //'dotted'虛線 'solid'實(shí)線
}
}
}
],
yAxis : [
{
name: '數(shù)量',
type : 'value',
splitLine: {
lineStyle: {
color: ['rgba(230, 230, 230, 0.2)'],
type:'dotted' //'dotted'虛線 'solid'實(shí)線
}
},
axisLine: {
lineStyle:{
color: '#fff',
type:'solid' //'dotted'虛線 'solid'實(shí)線
}
}
}
],
series : [
{
name:'直接訪問',
type:'bar',
data:[320, 332, 301, 334, 390, 330, 320]
},
{
name:'郵件營銷',
type:'bar',
stack: '廣告',
data:[120, 132, 101, 134, 90, 230, 210]
},
{
name:'聯(lián)盟廣告',
type:'bar',
stack: '廣告',
data:[220, 182, 191, 234, 290, 330, 310]
},
{
name:'視頻廣告',
type:'bar',
stack: '廣告',
data:[150, 232, 201, 154, 190, 330, 410]
},
{
name:'搜索引擎',
type:'bar',
data:[862, 1018, 964, 1026, 1679, 1600, 1570],
markLine : {
lineStyle: {
normal: {
type: 'dashed'
}
},
data : [
[{type : 'min'}, {type : 'max'}]
]
}
},
{
name:'百度',
type:'bar',
barWidth : 5,
stack: '搜索引擎',
data:[620, 732, 701, 734, 1090, 1130, 1120]
},
{
name:'谷歌',
type:'bar',
stack: '搜索引擎',
data:[120, 132, 101, 134, 290, 230, 220]
},
{
name:'必應(yīng)',
type:'bar',
stack: '搜索引擎',
data:[60, 72, 71, 74, 190, 130, 110]
},
{
name:'其他',
type:'bar',
stack: '搜索引擎',
data:[62, 82, 91, 84, 109, 110, 120]
}
]
};
if (option && typeof option === "object") {
this.mcChart.setOption(option, true);
};
// 綁定點(diǎn)擊事件
this.mcChart.on('click', function (params) {
console.log(params)
})
},
// 時(shí)間插件
onChangeDate(date) { // daterange改變的時(shí)候觸發(fā)的事件 默認(rèn)接收一個(gè)date對(duì)象
this.startTime = date[0];
this.endTime = date[1];
},
// 時(shí)間插件
okChange() { // 點(diǎn)擊確定按鈕觸發(fā)的事件
var params = {startTime: this.startTime, endTime: this.endTime}
if( params.startTime === '' || params.endTime=== '') {
this.$Message.info('請(qǐng)選擇日期范圍');
return
} else {
this._showPoint(params)
}
},
// 時(shí)間插件
onClear() {
console.log('今日實(shí)況')
},
},
mounted: function() {
this._mcCharts()
window.addEventListener('resize', function() { // 第一步:main中添加style="100%",第二步:添加.bind(this)
this.mcChart.resize()
}.bind(this));
},
components: {
'v-filter': filter
}
}項(xiàng)目截圖

地圖功能

餅圖功能+單選復(fù)選

復(fù)雜折線圖+單選復(fù)選

復(fù)雜柱狀圖+單選復(fù)選

百度地圖api實(shí)現(xiàn)跳點(diǎn)




大屏展示

以上就是Vue Echarts實(shí)現(xiàn)多功能圖表繪制的示例詳解的詳細(xì)內(nèi)容,更多關(guān)于Vue Echarts多功能圖表的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
Vue3中多個(gè)彈窗同時(shí)出現(xiàn)的解決思路
這篇文章主要介紹了Vue3中多個(gè)彈窗同時(shí)出現(xiàn)的解決思路,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-02-02
vue動(dòng)態(tài)禁用控件綁定disable的例子
今天小編就為大家分享一篇vue動(dòng)態(tài)禁用控件綁定disable的例子,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2019-10-10
VantUI封裝自定義Tabbar路由跳轉(zhuǎn)的實(shí)現(xiàn)
本文主要介紹了VantUI封裝自定義Tabbar路由跳轉(zhuǎn)的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-05-05
Vue3中element-plus全局使用Icon圖標(biāo)的過程詳解
我們?cè)谟胿ue開發(fā)網(wǎng)站的時(shí)候,往往圖標(biāo)是起著很重要的作,這篇文章主要給大家介紹了關(guān)于Vue3中element-plus全局使用Icon圖標(biāo)的相關(guān)資料,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2022-01-01
vuex 如何動(dòng)態(tài)引入 store modules
這篇文章主要介紹了vuex 如何動(dòng)態(tài)引入 store modules,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-03-03

