在vue中使用echarts實(shí)現(xiàn)上浮與下鉆效果
第一步:
在vue項(xiàng)目中安裝 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, 臺(tái)州市: 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, //單詞意思是漫步 實(shí)際是可以拖拽 label: { //文字的顏色 單詞意思標(biāo)簽 normal: { //靜態(tài)的時(shí)候顯示的默認(rèn)樣式 show: true, color: "#fff" }, emphasis: { //鼠標(biāo)移入動(dòng)態(tài)的時(shí)候顯示的默認(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)移入動(dòng)態(tài)的時(shí)候顯示區(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]; //對(duì)應(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 實(shí)現(xiàn)上浮與下鉆效果,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
如果你覺(jué)得本文對(duì)你有幫助,歡迎轉(zhuǎn)載,煩請(qǐng)注明出處,謝謝!
相關(guān)文章
vue自適應(yīng)布局postcss-px2rem詳解
這篇文章主要介紹了vue自適應(yīng)布局(postcss-px2rem)的相關(guān)知識(shí),本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友參考下吧2022-05-05如何配置vue.config.js 處理static文件夾下的靜態(tài)文件
這篇文章主要介紹了如何配置vue.config.js 處理static文件夾下的靜態(tài)文件,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-06-06Vue實(shí)現(xiàn)實(shí)時(shí)刷新時(shí)間的功能
這篇文章主要為大家詳細(xì)介紹了如何Vue利用實(shí)現(xiàn)實(shí)時(shí)刷新時(shí)間的功能,文中的示例代碼講解詳細(xì),具有一定的借鑒價(jià)值,感興趣的小伙伴可以了解下2023-12-12vue2之簡(jiǎn)易的pc端短信驗(yàn)證碼的問(wèn)題及處理方法
這篇文章主要介紹了vue2之簡(jiǎn)易的pc端短信驗(yàn)證碼的問(wèn)題,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-06-06UniApp中實(shí)現(xiàn)類似錨點(diǎn)定位滾動(dòng)效果
一個(gè)uniapp小程序的項(xiàng)目,我們需要實(shí)現(xiàn)一個(gè)非常實(shí)用的功能——類似于錨點(diǎn)定位的交互效果,即在首頁(yè)中有多個(gè)tab(分類標(biāo)簽),每個(gè)tab對(duì)應(yīng)著不同的模塊,當(dāng)用戶點(diǎn)擊某個(gè)分類的tab時(shí),需要流暢地滾動(dòng)到對(duì)應(yīng)的內(nèi)容位置,提供更好的用戶體驗(yàn),2023-10-10Vue源碼學(xué)習(xí)之初始化模塊init.js解析
本篇文章主要介紹了Vue源碼學(xué)習(xí)之初始化模塊init.js解析,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-11-11Vue獲取HTMLCollection列表的children時(shí)結(jié)果為undefined問(wèn)題
這篇文章主要介紹了Vue獲取HTMLCollection列表的children時(shí)結(jié)果為undefined問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-03-03