更新時間:2022-04-27 10:22:00 來源:動力節點 瀏覽2441次
Echarts官方文檔已經暫停了地圖數據的下載,但是百度Echarts給我們留了下載的官方接口:https://echarts.apache.org/examples/vendors/echarts/map/
(1)JSON格式
https://echarts.apache.org/examples/vendors/echarts/map/json/
(2)JS格式
https://echarts.apache.org/examples/vendors/echarts/map/js/
(1)下載china.js文件
https://echarts.apache.org/examples/vendors/echarts/map/js/china.js
(2)放到對應的文件(放在了utils里)
(3)上代碼
<template>
<div class="managingPatientSize">
<el-row>
<el-col :span="6">1</el-col>
<el-col :span="12">
<div id="china-map"></div>
</el-col>
<el-col :span="6">1</el-col>
</el-row>
</div>
</template>
<script>
import "../utils/china.js";
// 引入 ECharts 主模塊
var echarts = require("echarts/lib/echarts");
// 引入柱狀圖
require("echarts/lib/chart/bar");
require("echarts/lib/chart/line");
// 引入提示框和標題組件
require("echarts/lib/component/tooltip");
require("echarts/lib/component/title");
require("echarts/lib/chart/pie");
require("echarts/lib/component/markLine");
require("echarts/lib/component/geo");
require("echarts/lib/chart/scatter");
require("echarts/lib/chart/map");
export default {
data() {
return {};
},
mounted() {
this.drawCharts();
},
methods: {
drawCharts() {
// 基于準備好的dom,初始化echarts實例
var chinaMap = echarts.init(document.getElementById("china-map"));
window.onresize = chinaMap.resize; // 窗口或框架被調整大小時執行chinaMap.resize
chinaMap.setOption({
// 進行相關配置
tooltip: {}, // 鼠標移到圖里面的浮動提示框
dataRange: {
show: false,
min: 0,
max: 1000,
text: ["High", "Low"],
realtime: true,
calculable: true,
color: ["orangered", "#FF9B52", "#FFD068"],
},
geo: {
// 這個是重點配置區
map: "china", // 表示中國地圖
roam: true,
label: {
normal: {
show: true, // 是否顯示對應地名
textStyle: {
color: "#fff",
},
},
},
itemStyle: {
normal: {
borderColor: "#293171",
borderWidth: "2",
areaColor: "#0A0F33",
},
emphasis: {
areaColor: null,
shadowOffsetX: 0,
shadowOffsetY: 0,
shadowBlur: 20,
borderWidth: 0,
shadowColor: "rgba(0, 0, 0, 0.5)",
},
},
},
series: [
{
type: "scatter",
coordinateSystem: "geo", // 對應上方配置
},
{
name: "啟動次數", // 浮動框的標題
type: "map",
geoIndex: 0,
data: [
{
name: "北京",
value: 599,
},
{
name: "上海",
value: 142,
},
{
name: "黑龍江",
value: 44,
},
{
name: "深圳",
value: 92,
},
{
name: "湖北",
value: 810,
},
{
name: "四川",
value: 453,
},
],
},
],
});
},
},
};
</script>
<style lang="scss" scoped>
.managingPatientSize {
height: 100%;
color: #fff;
.el-row {
height: 100%;
.el-col {
height: 100%;
position: relative;
#china-map {
height: 100%;
}
}
}
}
</style>
(4)效果圖
0基礎 0學費 15天面授
有基礎 直達就業
業余時間 高薪轉行
工作1~3年,加薪神器
工作3~5年,晉升架構
提交申請后,顧問老師會電話與您溝通安排學習