vue使用echarts實現(xiàn)地圖的方法詳解
更新時間:2022年03月24日 15:11:20 作者:HerayChen
這篇文章主要為大家詳細(xì)介紹了vue使用echarts實現(xiàn)地圖的方法,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來幫助

全局安裝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é)點
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ù)組的第二個值
* formatter(params) {
return (
"<div>" +
params.data.name +
" <br> " +
"省份總額度:" +
params.data.value[2] +
"(萬元)</div>"
);
}
*/
},
series: [
{
type: 'map',
map: 'china',
geoIndex: 1,
showLegendSymbol: false, // 存在legend時顯示
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中實現(xiàn)拖動調(diào)整左右兩側(cè)div的寬度的示例代碼
這篇文章主要介紹了vue中實現(xiàn)拖動調(diào)整左右兩側(cè)div的寬度的示例代碼,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-07-07
Vue JS對URL網(wǎng)址進(jìn)行編碼解碼,轉(zhuǎn)換為對象方式
這篇文章主要介紹了Vue JS對URL網(wǎng)址進(jìn)行編碼解碼,轉(zhuǎn)換為對象方式,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-03-03
elementUI?checkBox報錯Cannot read property &ap
這篇文章主要為大家介紹了elementUI?checkBox報錯Cannot read property 'length' of undefined的解決分析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-06-06
Vue el-table表頭上引入組件不能實時傳參解決方法分析
這篇文章主要介紹了Vue el-table表頭上引入組件不能實時傳參解決方法,總的來說這并不是一道難題,那為什么要拿出這道題介紹?拿出這道題真正想要傳達(dá)的是解題的思路,以及不斷優(yōu)化探尋最優(yōu)解的過程。希望通過這道題能給你帶來一種解題優(yōu)化的思路2022-11-11
深入理解與使用keep-alive(配合router-view緩存整個路由頁面)
這篇文章主要介紹了深入理解與使用keep-alive(配合router-view緩存整個路由頁面),小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-09-09
Vue中Video標(biāo)簽播放解析后短視頻去水印無響應(yīng)解決
這篇文章主要為大家介紹了Vue中使用Video標(biāo)簽播放?<解析后的短視頻>去水印視頻無響應(yīng)的解決方式,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-04-04

