vue+echarts之地图下钻views/components/echarts/mapGraphDillDown.vue
<template>
<div class="home">
<div class="header" >
<el-button type="primary" @click="goBack">返回</el-button>
</div>
<div v-bind:id="id" >
</div>
</div>
</template>
<script>
/
/ 还要特别引⼊china.json,这样中国地图才会出现,不然只会出现右下⾓的南海诸岛
import china from "@/views/static/china";
import {
getAreaList,
getCityList,
getProvinceList,
} from "@/api/project/tag/tag";
export default {
name: "mapGraph",
data() {
return {
ChartMapDillDownGraph: null,
chartNum: 1,
myChart: null,
mapName:"china",
code:['china']
};
},
//  深度监听⽗组件刚开始没有值,只有图标的配置项
//  ⽗组件ajax请求后改变数据的值,传递过来,图标已⽣成,监听传过来的值的改变
// deep:true.深度监听,确保data中⼦项修改也能监听到。写法参考:/v2/api/#watch
watch: {
/
/ data: {
//  handler(newvalue, oldvalue) {
//    this.drawMapDillDownGraph(this.id, newvalue);
//  },
//  deep: true,
// },
},
props: ["id", "params"],
mounted() {
this.drawMapDillDownGraph(this.id, this.params);
},
methods: {
goBack(){
if(this.chartNum>1){
// alert(this.chartNum)
if(this.chartNum==4){
console.de);
this.chartNum=2
this.drawMapDillDownGraph(this.de.length-2]);
}else if(this.chartNum==3){
this.chartNum=1
this.drawMapDillDownGraph(this.id);
}
}
},
drawMapDillDownGraph(id, params) {
let _this = this;
let data ;
if (this.chartNum == 1) {
data = require(`../../static/china.json`);
this.$isterMap(this.mapName, data);
} else if (this.chartNum == 2) {
data = require('../../static/provinceCode/'+params+'.json');
go2map地图北京
this.mapName = "china"+params;
this.$isterMap(this.mapName, data);
} else if (this.chartNum == 3) {
data = require('../../static/city/'+params+'.json');
this.mapName = "china"+params;
this.$isterMap(this.mapName, data);
} else {
return;
}
this.chartNum !== 1 ? this.ChartMapDillDownGraph.dispose() : ""; // 创建新实例之前⼀定要销毁上⼀个实例,否则重复多次点击⽆数的实例导致内存爆满      this.chartNum++;
this.ChartMapDillDownGraph = this.$echarts.Chart);
if (this.chartNum == 2) {
//这个是为了测试异步的时候得到的数据(数据可以这样获得,通过接⼝)
getProvinceList().then((res) => {
let option = {
tooltip: {},
legend: {
orient: "vertical",
left: "left",
data: [""],
},
visualMap: {
min: 0,
max: 1500,
left: "10%",
top: "bottom",
text: ["⾼", "低"],
calculable: true,
color: ["#0b50b9", "#c3e2f4"],
},
selectedMode: "single",
series: [
{
name: "",
type: "map",
mapType: this.mapName,
itemStyle: {
normal: {
borderColor: "rgba(0, 0, 0, 0.2)",
},
emphasis: {
shadowOffsetX: 0,
shadowOffsetY: 0,
shadowBlur: 20,
borderWidth: 0,
shadowColor: "rgba(0, 0, 0, 0.5)",
},
},
showLegendSymbol: true,
label: {
normal: {
show: true,
},
emphasis: {
show: true,
},
},
data: [
{ name: "北京",id: "110000", value: 3455 },
{ id: "120000", value: 34 },
{ id: "上海", value: und(Math.random() * 500) },
{ name: "重庆", value: und(Math.random() * 500) },
{ id: "130000", value: 888 },
{ name: "河南",id: "410000", value: "河南" },
{ name: "云南", id: "530000", value: 23445 },
{ name: "辽宁", value: und(Math.random() * 500) },
{ name: "⿊龙江", value: und(Math.random() * 500) },
{ name: "湖南", value: und(Math.random() * 500) },
{ name: "安徽", value: und(Math.random() * 500) },
{ name: "⼭东", value: und(Math.random() * 500) },
{ name: "⼭东", value: und(Math.random() * 500) },                  { name: "新疆", value: und(Math.random() * 500) },                  { name: "江苏", value: und(Math.random() * 500) },                  { name: "浙江", value: und(Math.random() * 500) },                  { name: "江西", value: und(Math.random() * 500) },                  { name: "湖北", value: und(Math.random() * 500) },                  { name: "⼴西", value: und(Math.random() * 500) },                  { name: "⽢肃", value: und(Math.random() * 500) },                  { id: "140000", value: "356" },
{ name: "内蒙古", value: und(Math.random() * 500) },                  { name: "陕西", value: und(Math.random() * 500) },                  { name: "吉林", value: und(Math.random() * 500) },                  { name: "福建", value: und(Math.random() * 500) },                  { name: "贵州", value: und(Math.random() * 500) },                  { name: "⼴东", value: und(Math.random() * 500) },                  { name: "青海", value: und(Math.random() * 500) },                  { name: "西藏", value: und(Math.random() * 500) },                  { name: "四川", value: und(Math.random() * 500) },                  { name: "宁夏", value: und(Math.random() * 500) },                  { name: "海南", value: und(Math.random() * 500) },                  { name: "台湾", value: und(Math.random() * 500) },                  { name: "⾹港", value: und(Math.random() * 500) },                  { name: "澳门", value: und(Math.random() * 500) },                ],
},
],
};
this.ChartMapDillDownGraph.setOption(option);
});
} else if (this.chartNum == 3) {
let option = {
tooltip: {},
selectedMode: "single",
series: [
{
name: "",
type: "map",
mapType: this.mapName,
itemStyle: {
normal: {
borderColor: "rgba(0, 0, 0, 0.2)",
},
},
showLegendSymbol: true,
label: {
normal: {
show: true,
},
emphasis: {
show: true,
},
},
data: [{ name: "郑州市",id: "410100", value: "1111111" },
{ name: "保⼭市", id: "530600", value: 23445 }
],
},
],
};
this.ChartMapDillDownGraph.setOption(option);
} else if (this.chartNum == 4) {
let option = {
tooltip: {},
selectedMode: "single",
series: [
{
name: "",
type: "map",
mapType: this.mapName,
itemStyle: {
normal: {
borderColor: "rgba(0, 0, 0, 0.2)",
},
},
showLegendSymbol: true,

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。