echarts配置里颜色只能修改单个地图块的颜色,改变整体的有两个做法:
1.获取每个地图块方向和渐变色的值,每个单独写。
2.写两个地图,下面一层用不包含子区域的地图,上层的地图用透明色。
我用的第二种方法,具体如下:
先准备杭州市整体区域的json文件,和一个包含杭州各个区的json文件
地图json文件下载传送门
先引入需要的文件
| import geoJson from "./hangzhou.json"; |
| import hzJson from "./hz.json"; |
| var echarts = require("echarts/lib/echarts.js"); |
复制
methods方法里
| if (this.myChart) { |
| this.myChart.dispose(document.getElementById("hzChart")); |
| } |
| this.myChart = echarts.init(document.getElementById("hzChart")); |
| this.mapData = mapData; |
| echarts.registerMap("hangzhou", geoJson); |
| echarts.registerMap("hz", hzJson); |
| const option = { |
| tooltip: { |
| trigger: "item", |
| backgroundColor: "rgba(49, 97, 171, 0.75)", |
| borderColor: "rgba(127, 179, 255, 0.75)", |
| borderWeight: 3, |
| padding: 15, |
| formatter: (params) => { |
| const css = |
| "margin-bottom:8px;color: #FFF600;min-width:80px;font-size: 21px;"; |
| const text = ` |
| <p style="text-align: center; ${css}">${params.name}</p> |
| <p style="${css}">xx数:${params?.data?.Num || 0}</p> |
| <p style="${css}">xx数:${params?.data?.HanNum || 0}</p> |
| `; |
| return text; |
| }, |
| }, |
| geo: [ |
| |
| { |
| map: "hz", |
| zoom: 1.1, |
| roam: false, |
| itemStyle: { |
| normal: { |
| areaColor: { |
| |
| type: "linear", |
| x: 0, |
| y: 1, |
| x2: 0, |
| y2: 0, |
| colorStops: [ |
| { |
| offset: 1, |
| color: "RGBA(12, 93, 176, 0.5)", |
| }, |
| { |
| offset: 0, |
| color: "RGBA(38, 255, 228, 0.4)", |
| }, |
| ], |
| global: false, |
| }, |
| shadowColor: "rgb(58,115,192)", |
| shadowOffsetX: 2, |
| shadowOffsetY: 5, |
| borderColor: "RGBA(146, 255, 246, 0)", |
| borderWidth: 1, |
| }, |
| }, |
| }, |
| ], |
| series: [ |
| |
| { |
| type: "map", |
| roam: false, |
| mapType: "hangzhou", |
| map: "hangzhou", |
| zoom: 1.1, |
| label: { |
| normal: { |
| show: true, |
| textStyle: { |
| |
| color: "rgba(126, 233, 254, 1)", |
| fontSize: 16, |
| fontWeight: "700", |
| fontFamily: "FZZhengHeiS-B-GB", |
| }, |
| }, |
| }, |
| select: { |
| |
| label: { |
| color: "rgba(255, 246, 0, 1)", |
| }, |
| itemStyle: { |
| areaColor: "RGBA(18, 105, 167, 0.7)", |
| }, |
| }, |
| itemStyle: { 默认的样式 |
| normal: { |
| areaColor: "RGBA(20, 103, 183, 0)", |
| borderColor: "RGBA(146, 255, 246, 0.3)", |
| borderWidth: 1, |
| shadowBlur: 0, |
| color: "rgba(255, 246, 0, 1)", |
| }, |
| emphasis: { |
| areaColor: "RGBA(18, 105, 167, 0.7)", |
| label: { |
| show: true, |
| color: "rgba(255, 246, 0, 1)", |
| }, |
| }, |
| }, |
| data: mapData, |
| }, |
| ], |
| }; |
| this.myChart.setOption(option); |
复制