实现代码
import echarts from 'echarts'
import 'echarts/map/js/china'
export default {
name: 'timeDisplay',
data() {
return {
map: null,
mapOption: {
},
cities: {
},
provinces: {
},
data: [],
str: ''
}
},
methods: {
initMap() {
this.data = data;
this.cities = data.data.cities;
// 把省份数据映射为 echarts对应格式
this.provinces = data.data.provinces;
this.provinces = this.provinces.map(item => {
item.name = item.province;
item.value = item.sure_cnt;
// 给数据添加了英文名称
if (item.province == "湖北") {
item.en = "hubei"
} else if (item.province == "河南") {
item.en = "henan"
} else if (item.province == "湖南") {
item.en = "hunan"
}
return item;
})
// console.log(this.provinces)
this.map = echarts.init(this.$refs.maps);
this.mapOption = {
tooltip: {
formatter: (e) => {
this.str =
`<strong>${
e.data&&e.name?e.data.name:''}:</strong><br/>累计确诊:${
e.data.sure_cnt||