vue使用echarts實(shí)現(xiàn)地圖的方法詳解
全局安裝echarts
npm i echarts --save
將echarts綁定在原型上(main.js文件中)
import * as echarts from 'echarts'; Vue.prototype.$echarts = echarts;
準(zhǔn)備畫布
<template> <div ref="openingChart" style="height: 600px;"></div> </template>
<script> import china from "../store/china.json"; export default { methods: { initCharts() { // 初始化中國地圖 this.$echarts.registerMap("china", china); // 獲取dom節(jié)點(diǎn) let openingChart= this.$echarts.init(this.$refs.openingChart); // option配置寫在最下面的 openingChart.setOption(option); window.addEventListener("resize", () => { openingBankChart.resize(); }); } }, mounted() { this.initCharts(); } } </script>
地圖配置option
option = { // 地圖背景色 backgroundColor: "#ccd3e4", geo: { map: 'china', }, tooltip: { trigger: 'item', // 自定義提示框的內(nèi)容 /** 這里自定義顯示的值是data中value數(shù)組的第二個(gè)值 * formatter(params) { return ( "<div>" + params.data.name + " <br> " + "省份總額度:" + params.data.value[2] + "(萬元)</div>" ); } */ }, series: [ { type: 'map', map: 'china', geoIndex: 1, showLegendSymbol: false, // 存在legend時(shí)顯示 tooltip: { show: false }, label: { normal: { show: false }, emphasis: { show: false } }, roam: false, itemStyle: { normal: { areaColor: "#aaa", borderColor: "#ccd3e4", borderWidth: 1, }, emphasis: { areaColor: "#aaa", }, }, }, { name: '省份總額度', type: 'effectScatter', coordinateSystem: 'geo', data: [{ name: "深圳", value: [121.15, 31.89, 12], }, { name: "武漢", value: [109.781327, 39.608266, 29] }], symbolSize: 20, symbol: 'circle', label: { normal: { show: false, }, emphasis: { show: false, }, }, showEffectOn: "render", itemStyle: { normal: { color: { type: "radial", colorStops: [ { offset: 0, color: "#e5c68b", }, { offset: 0.8, color: "#6e96d4", }, { offset: 1, color: "#6e96d4", }, ], global: false, // 缺省為 false }, }, }, }, ] }
中國地圖包(china.json)
總結(jié)
本篇文章就到這里了,希望能夠給你帶來幫助,也希望您能夠多多關(guān)注腳本之家的更多內(nèi)容!
相關(guān)文章
vue中實(shí)現(xiàn)拖動(dòng)調(diào)整左右兩側(cè)div的寬度的示例代碼
這篇文章主要介紹了vue中實(shí)現(xiàn)拖動(dòng)調(diào)整左右兩側(cè)div的寬度的示例代碼,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-07-07Vue JS對(duì)URL網(wǎng)址進(jìn)行編碼解碼,轉(zhuǎn)換為對(duì)象方式
這篇文章主要介紹了Vue JS對(duì)URL網(wǎng)址進(jìn)行編碼解碼,轉(zhuǎn)換為對(duì)象方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-03-03elementUI?checkBox報(bào)錯(cuò)Cannot read property &ap
這篇文章主要為大家介紹了elementUI?checkBox報(bào)錯(cuò)Cannot read property 'length' of undefined的解決分析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-06-06移動(dòng)端調(diào)試神器vConsole使用詳解
vConsole?是框架無關(guān)的,可以在?Vue、React?或其他任何框架中使用,今天通過本文給大家介紹移動(dòng)端調(diào)試神器vConsole使用,感興趣的朋友一起看看吧2022-04-04Vue el-table表頭上引入組件不能實(shí)時(shí)傳參解決方法分析
這篇文章主要介紹了Vue el-table表頭上引入組件不能實(shí)時(shí)傳參解決方法,總的來說這并不是一道難題,那為什么要拿出這道題介紹?拿出這道題真正想要傳達(dá)的是解題的思路,以及不斷優(yōu)化探尋最優(yōu)解的過程。希望通過這道題能給你帶來一種解題優(yōu)化的思路2022-11-11深入理解與使用keep-alive(配合router-view緩存整個(gè)路由頁面)
這篇文章主要介紹了深入理解與使用keep-alive(配合router-view緩存整個(gè)路由頁面),小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-09-09Vue使用自定義指令實(shí)現(xiàn)拖拽行為實(shí)例分析
這篇文章主要介紹了Vue使用自定義指令實(shí)現(xiàn)拖拽行為,結(jié)合實(shí)例形式分析了Vue使用自定義指令實(shí)現(xiàn)拖拽行為具體步驟、原理與操作注意事項(xiàng),需要的朋友可以參考下2020-06-06Vue中Video標(biāo)簽播放解析后短視頻去水印無響應(yīng)解決
這篇文章主要為大家介紹了Vue中使用Video標(biāo)簽播放?<解析后的短視頻>去水印視頻無響應(yīng)的解決方式,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-04-04