在vue中使用echarts實現(xiàn)上浮與下鉆效果
第一步:
在vue項目中安裝 echarts
npm i echars -S
第二步:
main.js配置 這里是全局引入
//引入echars import echarts from 'echarts' Vue.prototype.$echarts = echarts
第三步
直接上代碼
<template>
<div id="container">
<header>浙江省echars地圖</header>
<div id="echarsMap"></div>
</div>
</template>
<script>
//引入json
import zhejiang from "../../../static/zhejiangJson/zhejiang";
import hangzhou from "../../../static/zhejiangJson/hangzhou";
import huzhou from "../../../static/zhejiangJson/huzhou";
import jiaxing from "../../../static/zhejiangJson/jiaxing";
import jinhua from "../../../static/zhejiangJson/jinhua";
import lanzhou from "../../../static/zhejiangJson/lanzhou";
import lishui from "../../../static/zhejiangJson/lishui";
import ningbo from "../../../static/zhejiangJson/ningbo";
import quzhou from "../../../static/zhejiangJson/quzhou";
import shaoxing from "../../../static/zhejiangJson/shaoxing";
import taizhou from "../../../static/zhejiangJson/taizhou";
import wenzhou from "../../../static/zhejiangJson/wenzhou";
import zhoushan from "../../../static/zhejiangJson/zhoushan";
export default {
name: "echars1",
data() {
return {
cityName: "",//區(qū)域的名字
markerArr: [], //接收散點(diǎn)圖數(shù)據(jù)
};
},
methods: {
//畫地圖
initEchars(cityName) {
var cityMap = {
杭州市: hangzhou,
麗水市: lishui,
蘭州市: lanzhou,
臺州市: taizhou,
嘉興市: jiaxing,
寧波市: ningbo,
溫州市: wenzhou,
湖州市: huzhou,
紹興市: shaoxing,
舟山市: zhoushan,
衢州市: quzhou,
金華市: jinhua
};
var name = [cityName];
var pos = {
leftPlus: 115,
leftCur: 150,
left: 198,
top: 50
};
var line = [[0, 0], [8, 11], [0, 22]];
// style
var style = {
font: '18px "Microsoft YaHei", sans-serif',
textColor: "#eee",
lineColor: "rgba(147, 235, 248, .8)"
};
if (cityName == "" || cityName == "浙江") {
cityName = "浙江";
this.$echarts.registerMap("浙江", zhejiang);
}
let mapCharts = this.$echarts.init(document.getElementById("echarsMap"));
let mapCharts_option = {
//鼠標(biāo)懸浮點(diǎn)標(biāo)記
// tooltip: {
// padding: 0,
// enterable: true,
// transitionDuration: 1,
// textStyle: {
// color: "#000",
// decoration: "none"
// },
// formatter: function(params) {
// var tipHtml = "";
// tipHtml =
// '<div style="width:100%;height:auto;background:rgba(22,80,158,1);border:1px solid rgba(7,166,255,0.7)">' +
// '<div style="width:100%;height:40px;line-height:40px;border-bottom:2px solid rgba(7,166,255,0.7);padding:0 20px">' +
// '<i style="display:inline-block;width:8px;height:8px;background:#16d6ff;border-radius:40px;">' +
// "</i>" +
// '<span style="margin-left:10px;color:#fff;font-size:16px;">' +
// params.data.org_name +
// "</span>" +
// "</div>" +
// '<div style="padding:20px">' +
// '<p style="color:#fff;font-size:12px;">' +
// '<i style="display:inline-block;width:10px;height:10px;background:#16d6ff;border-radius:40px;margin:0 8px">' +
// "</i>" +
// "工程名稱:" +
// '<span style="color:#f48225;margin:0 6px;">' +
// params.data.name +
// "</span>" +
// "</p>" +
// "</div>" +
// "</div>";
// return tipHtml;
// }
// },
//單詞意思 圖形圖表
graphic: [
{
type: "group",
left: pos.left,
top: pos.top - 4,
children: [
{
type: "line",
left: 0,
top: -20,
shape: {
x1: 0,
y1: 0,
x2: 60,
y2: 0
},
style: {
stroke: style.lineColor
}
},
{
type: "line",
left: 0,
top: 20,
shape: {
x1: 0,
y1: 0,
x2: 60,
y2: 0
},
style: {
stroke: style.lineColor
}
}
]
},
{
id: "",
type: "group",
left: pos.left + 2,
top: pos.top,
children: [
{
type: "polyline",
left: 90,
top: -12,
shape: {
points: line
},
style: {
stroke: "transparent",
key: name[0]
},
onclick: function() {}
},
{
type: "text",
left: 0,
top: "middle",
style: {
text: "浙江",
textAlign: "center",
fill: style.textColor,
font: style.font
},
onclick: () => {
mapCharts.clear();
this.$echarts.registerMap("浙江", zhejiang);
mapCharts_option.geo.map = "浙江";
mapCharts.setOption(mapCharts_option, true);
}
},
{
type: "text",
left: 0,
top: 10,
style: {
text: "zhejiang",
textAlign: "center",
fill: style.textColor,
font: '12px "Microsoft YaHei", sans-serif'
},
onclick: () => {
mapCharts.clear();
this.$echarts.registerMap("浙江", zhejiang);
mapCharts_option.geo.map = "浙江";
mapCharts.setOption(mapCharts_option, true);
}
}
]
}
],
//設(shè)置地圖
geo: {
map: cityName,
zoom: "1.2", //縮放比例
scaleLimit: {
//縮放的限度
min: 1,
max: 30
},
roam: true, //單詞意思是漫步 實際是可以拖拽
label: {
//文字的顏色 單詞意思標(biāo)簽
normal: {
//靜態(tài)的時候顯示的默認(rèn)樣式
show: true,
color: "#fff"
},
emphasis: {
//鼠標(biāo)移入動態(tài)的時候顯示的默認(rèn)樣式
// show: false,
// color:'#333'
}
},
itemStyle: {
//區(qū)域設(shè)置
normal: {
borderColor: "rgba(147, 235, 248, 1)",
borderWidth: 1,
areaColor: {
type: "radial",
x: 0.5,
y: 0.5,
r: 0.8,
colorStops: [
{
offset: 0,
color: "rgba(147, 235, 248, 0)" // 0% 處的顏色
},
{
offset: 1,
color: "rgba(147, 235, 248, .2)" // 100% 處的顏色
}
],
globalCoord: false // 缺省為 false
},
shadowColor: "rgba(128, 217, 248, 1)",
shadowOffsetX: -2,
shadowOffsetY: 2,
shadowBlur: 10
},
emphasis: {
//鼠標(biāo)移入動態(tài)的時候顯示區(qū)域顏色
areaColor: "#389BB7",
borderWidth: 0
}
}
},
series: [] //存點(diǎn)標(biāo)記的地方
};
mapCharts.clear();
mapCharts.setOption(mapCharts_option, true);
mapCharts.resize();
mapCharts.on("click", params => {
//地圖下鉆
console.log(params);
if (cityMap[params.name]) {
this.cityName = params.name;
var url = cityMap[params.name]; //對應(yīng)的拼音區(qū)域
this.$echarts.registerMap(params.name, url);
mapCharts_option.geo.map = params.name;
mapCharts.setOption(mapCharts_option, true);
}
});
},
},
mounted() {
this.initEchars("浙江");
}
};
</script>
<style lang="less" scoped>
#container {
width: 100%;
height: calc(100% - 78px);
background-color: pink;
#echarsMap {
width: 80%;
height: 80%;
background-color: #000;
margin: auto;
}
}
</style>效果圖

點(diǎn)擊下一層

總結(jié)
以上所述是小編給大家介紹的在vue中使用 echarts 實現(xiàn)上浮與下鉆效果,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
如果你覺得本文對你有幫助,歡迎轉(zhuǎn)載,煩請注明出處,謝謝!
相關(guān)文章
vue自適應(yīng)布局postcss-px2rem詳解
這篇文章主要介紹了vue自適應(yīng)布局(postcss-px2rem)的相關(guān)知識,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友參考下吧2022-05-05
如何配置vue.config.js 處理static文件夾下的靜態(tài)文件
這篇文章主要介紹了如何配置vue.config.js 處理static文件夾下的靜態(tài)文件,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-06-06
UniApp中實現(xiàn)類似錨點(diǎn)定位滾動效果
一個uniapp小程序的項目,我們需要實現(xiàn)一個非常實用的功能——類似于錨點(diǎn)定位的交互效果,即在首頁中有多個tab(分類標(biāo)簽),每個tab對應(yīng)著不同的模塊,當(dāng)用戶點(diǎn)擊某個分類的tab時,需要流暢地滾動到對應(yīng)的內(nèi)容位置,提供更好的用戶體驗,2023-10-10
Vue源碼學(xué)習(xí)之初始化模塊init.js解析
本篇文章主要介紹了Vue源碼學(xué)習(xí)之初始化模塊init.js解析,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-11-11
Vue獲取HTMLCollection列表的children時結(jié)果為undefined問題
這篇文章主要介紹了Vue獲取HTMLCollection列表的children時結(jié)果為undefined問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-03-03

