<template>
<div class="echarts-contain map-echarts">
<charts :option="chinaMapOption"></charts>
</div>
</template>
<script>
import { reactive } from 'vue';
import echarts from 'echarts';
import option from "./map-option.js";
const state = reactive({
seriesData: [
{ name: '北京市', value: 15477.48 },
{ name: '上海市', value: 31686.1 }
],
chinaMapOption: {}
})
const initChinaMap = async () => {
const res: any = await axios.get('/chinaMap.json')
echarts.registerMap('china', res.data)
state.chinaMapOption = {
title: {
text: "中国地图",
left: 'center',
top: 20
},
tooltip: {
trigger: 'item',
formatter: function (params: { name: string, value: unknown }) {
return `${params.name}: ${params.value || '-'}`
}
},
grid: {
left: '10px',
right: '10px',
top: '10px',
bottom: '10px'
},
visualMap: {
min: 800,
max: 50000,
text: ['High', 'Low'],
realtime: false,
calculable: true,
inRange: {
color: ['lightskyblue', 'yellow', 'orangered']
}
},
series: [
{
type: 'map',
map: 'china',
data: state.seriesData,
}
]
}
}
onMounted(() => {
initChinaMap()
})
const { chinaMapOption } = toRefs(state)
</script>
|