介绍

官方介绍地址open in new window

官方提供的案例地址

官方demo地址open in new window

本次案例 地图渲染

<template>
	<view class="p20">
		<view class="analysisCardTitle ml20">
			各区域客户分布情况
		</view>
		<view class="echarts" @click="echarts.onClick" :prop="options" :change:prop="echarts.updateEcharts"
			id="echarts">
			
		</view>

	</view>
</template>

<script>
	import {
		map
	} from '@/api/modules/analysis.js'
	import china from "./map.json";  //案例地图数据 开源去 我开源模板演示案例获取数据地址
	//引用配置文件 用于改写样式覆盖使用
	export default {
		props: {
			height: {
				type: String,
				default: "1100rpx"
			}
		},
		data() {
			return {
				options: {
					  toolbox: {
					    left: 'right',
					    itemSize: 12,
					    top: 0,
					    feature: {
					      
					      restore: {}
					    }
					  },
				
					series: [{
						type: "map",
						roam: true,
						zoom: 1,
						map: "china",
						top: 20,
						tooltip: {
							padding: 8,
							borderWidth: 1,
							borderColor: "#409eff",
							backgroundColor: "rgba(255,255,255,0.7)",
							textStyle: {
								color: "#000000",
								fontSize: 13,
							},
						

						},
						data: []
					}, ],
					tooltip: {
						trigger: "item",
					},
					visualMap: {
						//地图图例
						show: true,
						left: 26,
						bottom: 100,
						itemHeight: 80,
						itemWidth: 15,
						showLabel: true,
						min: 0,
						max: 3000,
						// text: ['High', 'Low'],
						realtime: false,
						calculable: true,
				  inRange: {
							color: ['lightskyblue', 'yellow', 'orangered']
						}
					},
				},

				form: {
					date: []
				},
			}



		},
		created() {

			//自定义格式化Tooltip显示内容
			this.form.date = [
				this.$getDate().date.starDate,
				this.$getDate().date.endDate,
			]
			this.getData()
		},
		methods: {
			onViewClick(options) {
				console.log(options)
			},
			getData() {
				map(this.form)
					.then(res => {
						this.options.series[0].data = res.data
		
					})
			},


		}
	};
</script>
<script module="echarts" lang="renderjs">
	import * as echarts from "echarts"
	import china from "./map.json";
	let myChart
	export default {
		mounted() {
			this.initEcharts()

		},
		methods: {
			updateEcharts(newValue, oldValue, ownerInstance, instance) {
				// 监听 service 层数据变更
				myChart.setOption(newValue,true)
			},
			onClick(event, ownerInstance) {
				// 调用 service 层的方法
				ownerInstance.callMethod('onViewClick', {
					test: 'test'
				})
			},
			initEcharts() {
				echarts.registerMap("china", china);
				myChart = echarts.init(document.getElementById('echarts'))
				// console.log(myChart.setOption);
				// 观测更新的数据在 view 层可以直接访问到
				this.options.series[0].tooltip.formatter= function(e, t, n) {
				     let data = e.data?e.data:{
						 name:"",
						 value:0,
						 prop:0,
					 };
					 console.log(data);
				     let context = `
				        <div>
				            <p><b style="font-size:15px;">${data.name}</b></p>
				            <p class="tooltip_style"><span class="tooltip_left">城市</span><span class="tooltip_right">${data.value?data.value:0}</span></p>
				            <p class="tooltip_style"><span class="tooltip_left">占比</span><span class="tooltip_right">${data.prop?data.prop:"0%"}</span></p>
				        </div>
				     `;
				     return context;
				   }
				myChart.setOption(this.options,true)
			},

		},
	}
</script>
<style scoped>
	.echarts {
		width: 100%;
		height: 400px;
	}
</style>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168