用vue编写,echarts省份地图,可以下钻到市县,引用了省份json文件,看着有点懵,后期就重新整理了一下

9 篇文章 0 订阅

图片:

直接复制下面代码到文件,即可显示:

index.vue

<style lang="less">

.o-echarts {

min-width: 30px;

min-height: 30px;

width: 100%;

height: 100%;

}

</style>

<template>

<div :id="id" class="o-echarts"></div>

</template>

 

<script>

 

import echarts from 'echarts';

import JSON from '../json/shandong.json';

 

export default {

name: 'echart-map',

data() {

return {

id: 'echarts_' + new Date().getTime() + Math.floor(Math.random() * 1000),

echartObj: null,

radioList: {

A: '年度总项目数据查询',

B: '军转干部在岗培训项目',

C: '专技人员公需科目项目',

D: '专技人员新取得中级职称岗前培训项目',

E: '事业单位新进人员岗前培训项目'

},

radioActive: 'A',

option: {

title: {

text: '选择所要查询的数据维度',

top: '3%',

left: '5%',

textStyle: {

fontSize: 18,

fontWeight: 300,

color: '#b6d7ff'

}

},

tooltip: {

padding: 0,

backgroundColor: 'transparent',

formatter: params => {

// params.data

return `<table class="map__tooltip o_font20">

<thead>

<tr>

<th>总购买人数</th>

<th>本年度总购买人数</th>

<th>本月度总购买人数</th>

<th>总完成人数</th>

</tr>

</thead>

<tbody>

<tr>

<th>${params.data.obj.a}</th>

<th>${params.data.obj.b}</th>

<th>${params.data.obj.c}</th>

<th>${params.data.obj.d}</th>

</tr>

</tbody>

</table>`;

}

},

legend: {

orient: 'vertical',

top: '9%',

left: '5%',

icon: 'circle',

data: [],

selectedMode: 'single',

selected: {},

itemWidth: 12,

itemHeight: 12,

itemGap: 30,

inactiveColor: '#b6d7ff',

textStyle: {

color: '#ec808d',

fontSize: 14,

fontWeight: 300,

padding: [0, 0, 0, 15]

}

},

visualMap: {

min: 0,

max: 500,

show: false,

splitNumber: 5,

inRange: {

color: ['#FACD91', '#74DFB2', '#81D3F8', '#768FDE', '#e9969f'].reverse()

},

textStyle: {

color: '#fff'

}

},

geo: {

map: '重庆',

label: {

normal: {

show: true,

color: '#000'

},

emphasis: {

show: true,

color: '#fff'

}

},

roam: false,

itemStyle: {

normal: {

areaColor: '#8db200',

borderColor: '#6367ad',

borderWidth: 1

},

emphasis: {

areaColor: '#feb6aa' // hover效果

}

},

left: '5%',

right: '5%',

top: '5%',

bottom: '5%'

},

series: [{

name: '年度总项目数据查询',

type: 'map',

geoIndex: 0, // 不可缺少,否则无tooltip 指示效果

data: []

}]

}

};

},

mounted() {

this.echartObj = echarts.init(document.getElementById(this.id));

echarts.registerMap('重庆', JSON);

this.echartObj.setOption(this.getOptions(), true);

this.echartObj.on('legendselectchanged', params => {

this.radioActive = Object.keys(this.radioList).filter(item => this.radioList[item] === params.name)[0];

this.echartObj.clear();

this.echartObj.setOption(this.getOptions());

});

window.addEventListener('resize', () => {

if (this.echartObj && this.echartObj.resize) {

this.echartObj.resize();

}

});

},

methods: {

getOptions() {

this.setOptions('legend', {

data: Object.values(this.radioList),

selected: (list => {

const obj = {};

Object.keys(list).map((item, index) => {

obj[list[item]] = item === this.radioActive;

});

return obj;

})(this.radioList)

});

this.setOptions('series', (() => {

const arr = [];

Object.values(this.radioList)

.map((item, index) => {

arr[this.radioList[this.radioActive] === item ? 'unshift' : 'push']({

name: item,

type: 'map',

geoIndex: 0, // 不可缺少,否则无tooltip 指示效果

data: this.getSeriesData(item)

});

});

return arr;

})());

return this.option;

},

getSeriesData(item) {

return this.radioList[this.radioActive] === item ? JSON.features.map(item => {

return {

name: item.properties.name,

value: Math.ceil(Math.random() * 500),

obj: {

a: Math.ceil(Math.random() * 500),

b: Math.ceil(Math.random() * 500),

c: Math.ceil(Math.random() * 500),

d: Math.ceil(Math.random() * 500)

}

};

}) : [];

},

setOptions(objKey, objVal) {

if (this.option[objKey] && typeof this.option[objKey] === 'object' && !Array.isArray(this.option[objKey])) {

this.option[objKey] = Object.assign(this.option[objKey], objVal);

} else {

this.option[objKey] = objVal;

}

this.$set(this.option, objKey, this.option[objKey]);

}

}

};

</script>

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
Vue中使用echarts获取省份地图,你可以按照以下步骤进行操作。 首先,你需要引入需要的echarts包和对应的省份地图。你可以使用import语句引入echarts包,并在Vue的组件中使用import语句引入对应的省份地图。例如,你可以使用以下代码引入echarts和湖北省的地图: ```javascript import echarts from "echarts/lib/echarts" import "echarts/map/js/province/hubei.js"; ``` 接下来,你需要在main.js文件中引入echarts并将其挂载到Vue的原型上。你可以使用以下代码实现: ```javascript import * as echarts from 'echarts' Vue.prototype.$echarts = echarts ``` 这样,你就可以在Vue组件中通过`this.$echarts`来使用echarts。 然后,你可以在Vue组件中使用echarts来实现获取省份地图的功能。你可以在该组件的方法中使用echarts的相关API来绘制地图和处理交互。具体的实现方式可以参考echarts官方文档的示例和地图相关的API。你可以在echarts官网的示例页面(https://echarts.apache.org/examples/zh/index.html)和地图相关的API文档(https://echarts.apache.org/zh/option.html#series-map)中找到更多的参考资料。 总结起来,你需要引入echarts包和对应的省份地图,将echarts挂载到Vue的原型上,并在Vue组件中使用echarts的API来实现获取省份地图的功能。希望这些信息对你有所帮助!<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [vue - vue使用echarts实现中国地图和点击省份进行查看](https://blog.csdn.net/qq_43886365/article/details/128102076)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *2* [vue echarts 3D地图+省+弹窗](https://blog.csdn.net/coldriversnow/article/details/117927061)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

xingchen678

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值