0


echarts 地图区域显示不同颜色笔记

  1. <template>
  2. <div class="map">
  3. <div class="map_chart" ref="map_chart"></div>
  4. </div>
  5. </template>
  6. <script>
  7. import axios from "axios";
  8. import {mapData} from '../utils/map'
  9. export default {
  10. name: "Map",
  11. data() {
  12. return {
  13. chartInstance: null,
  14. allData: null,
  15. mapData: {}, // 所获取的省份的地图矢量数据
  16. dataList:[
  17. {name: '庐阳区', value: 101},
  18. {name: '肥东县', value: 101},
  19. {name: '濉溪县', value: 101},
  20. {name: '埇桥区', value: 18},
  21. {name: '萧县', value: 101},
  22. {name: '蚌山区', value: 101},
  23. {name: '颍泉区', value: 101},
  24. {name: '临泉县', value: 101},
  25. {name: '太和县', value: 101},
  26. {name: '舒城县', value: 101},
  27. {name: '当涂县', value: 101},
  28. {name: '南陵县', value: 101},
  29. {name: '宣州区', value: 101},
  30. {name: '郎溪县', value: 101},
  31. {name: '广德市', value: 101},
  32. {name: '泾县', value: 101},
  33. {name: '休宁县', value: 101},
  34. ],
  35. nameStr:'庐阳区肥东县濉溪县埇桥区萧县蚌山区颍泉区临泉县太和县舒城县当涂县南陵县宣州区郎溪县广德市泾县休宁县'
  36. };
  37. },
  38. created() {},
  39. mounted() {
  40. this.initChart();
  41. window.addEventListener("resize", this.screenAdapter);
  42. },
  43. destroyed() {
  44. window.removeEventListener("resize", this.screenAdapter);
  45. },
  46. methods: {
  47. async initChart() {
  48. this.chartInstance = this.$echarts.init(this.$refs.map_chart);
  49. // 获取中国地图的矢量数据
  50. // http://localhost:8999/static/map/china.json
  51. // 由于我们现在获取的地图矢量数据并不是位于KOA2的后台, 所以咱们不能使用this.$http
  52. this.$echarts.registerMap("anhui", mapData);
  53. const initOption = {
  54. // title: {
  55. // text: "▎ 公墓分布",
  56. // left: 20,
  57. // top: 20,
  58. // },
  59. toolbox: {
  60. show: true,
  61. feature: {
  62. saveAsImage: {
  63. show:true
  64. }
  65. }
  66. }, // 提供下载工具
  67. // visualMap: {
  68. // min: 0,
  69. // max: 100000,
  70. // left: 26,
  71. // bottom: 40,
  72. // showLabel: !0,
  73. // // text: ["土葬", "智慧殡葬"],
  74. // pieces: [{
  75. // gte: 1,
  76. // lt: 100,
  77. // label: "土葬区",
  78. // color: "red",
  79. // }, {
  80. // gte: 100,
  81. // lt: 1000,
  82. // label: "土葬区",
  83. // color: "#ff3990",
  84. // },
  85. // {
  86. // gt: 1000,
  87. // lt: 10000,
  88. // label: "智慧殡葬",
  89. // color: "#f2d5ad"
  90. // }],
  91. // show: false
  92. // },
  93. geo: {
  94. // type: "map",
  95. map: "anhui",
  96. // 默认设置完地图是固定死的不能拖动
  97. // roam:true,//否开启鼠标缩放和平移漫游。默认不开启。
  98. roam: 1,
  99. //zoom :1,//当前视角的缩放比例。越大比例越大
  100. // center:[108.956239,34.268309],//当前视角的中心点,用经纬度表示108.956239,34.268309
  101. // label:{//地图上显示文字提示信息
  102. // show:true,
  103. // // color:"#ff6600",
  104. // fontSize:10//字体大小
  105. // },
  106. label: {
  107. normal: {
  108. // formatter:(params)=>{
  109. // console.log(params,'747')
  110. // // if(params.name=="庐阳区"||params.name=="肥东县"||params.name=="濉溪县"||params.name=="埇桥区"||params.name=="萧县"||params.name=="蚌山区"||params.name=="颍泉区"||params.name=="临泉县"||params.name=="太和县"||params.name=="舒城县"||params.name=="当涂县"||params.name=="南陵县"){
  111. // // return params.name
  112. // // }else{
  113. // // return ''
  114. // // }
  115. // if(this.nameStr.includes(params.name)){
  116. // return params.name
  117. // }else{
  118. // return ''
  119. // }
  120. // },
  121. show: !0,
  122. fontSize: "7",
  123. color: "#000"
  124. }
  125. },
  126. itemStyle: {
  127. normal: {
  128. areaColor: "#f2d5ad",
  129. // areaColor: "#ff3940",
  130. //shadowBlur: 50,
  131. //shadowColor: 'rgba(0, 0, 0, 0.2)',
  132. borderColor: "rgba(0, 0, 0, 0.2)"
  133. },
  134. emphasis: {
  135. areaColor: "#ff6600",
  136. shadowOffsetX: 0,
  137. shadowOffsetY: 0,
  138. borderWidth: 0
  139. }
  140. }
  141. // itemStyle:{//地图区域的多边形 图形样式。
  142. // areaColor:"#ff6600"//地图区域的颜色。
  143. // }
  144. // label: {
  145. // show: true,
  146. // color: "#1DE9B6",
  147. // },
  148. },
  149. // legend: {
  150. // left: '5%',
  151. // bottom: '5%',
  152. // orient: 'vertical'
  153. // },
  154. series:[
  155. {
  156. name: "殡葬",
  157. type: "map",
  158. geoIndex: 0,
  159. data: this.dataList
  160. }
  161. ]
  162. };
  163. this.chartInstance.setOption(initOption);
  164. this.chartInstance.on("click", async (arg) => {
  165. // arg.name 得到所点击的省份, 这个省份他是中文
  166. });
  167. },
  168. },
  169. };
  170. </script>
  171. <style scoped>
  172. .map {
  173. width: 100%;
  174. height: 100%;
  175. }
  176. .map_chart {
  177. width: 600px;
  178. height: 800px;
  179. margin:0 auto;
  180. }
  181. </style>

  1. <template>
  2. <div class="map">
  3. <div class="map_chart" ref="map_chart"></div>
  4. </div>
  5. </template>
  6. <script>
  7. import axios from "axios";
  8. import {mapData} from '../utils/map'
  9. export default {
  10. name: "Map",
  11. data() {
  12. return {
  13. chartInstance: null,
  14. allData: null,
  15. mapData: {}, // 所获取的省份的地图矢量数据
  16. dataList:[
  17. {name: '金寨县', value: 18},
  18. {name: '岳西县', value: 18},
  19. {name: '旌德县', value: 18},
  20. {name: '绩溪县', value: 18},
  21. {name: '休宁县', value: 18},
  22. {name: '歙县', value: 18},
  23. {name: '黟县', value: 18},
  24. {name: '祁门县', value: 18},
  25. {name: '石台县', value: 18},
  26. {name: '青阳县', value: 18},
  27. {name: '东至县', value: 18},
  28. {name: '黄山区', value: 18},
  29. ],
  30. names:['东至县','黄山区','金寨县','岳西县','旌德县','绩溪县','休宁县','歙县','黟县','祁门县','石台县','青阳县',]
  31. };
  32. },
  33. created() {},
  34. mounted() {
  35. this.initChart();
  36. window.addEventListener("resize", this.screenAdapter);
  37. },
  38. destroyed() {
  39. window.removeEventListener("resize", this.screenAdapter);
  40. },
  41. methods: {
  42. async initChart() {
  43. this.chartInstance = this.$echarts.init(this.$refs.map_chart);
  44. // 获取中国地图的矢量数据
  45. // http://localhost:8999/static/map/china.json
  46. // 由于我们现在获取的地图矢量数据并不是位于KOA2的后台, 所以咱们不能使用this.$http
  47. this.$echarts.registerMap("anhui", mapData);
  48. const initOption = {
  49. // title: {
  50. // text: "▎ 公墓分布",
  51. // left: 20,
  52. // top: 20,
  53. // },
  54. toolbox: {
  55. show: true,
  56. feature: {
  57. saveAsImage: {
  58. show:true
  59. }
  60. }
  61. }, // 提供下载工具
  62. visualMap: {
  63. min: 0,
  64. max: 100000,
  65. left: 26,
  66. bottom: 40,
  67. showLabel: !0,
  68. // text: ["土葬", "智慧殡葬"],
  69. pieces: [{
  70. gte: 1,
  71. lt: 100,
  72. label: "土葬区",
  73. color: "#ff3940",
  74. }, {
  75. gt: 100,
  76. lt: 1000,
  77. label: "智慧殡葬",
  78. color: "#f2d5ad"
  79. }],
  80. show: false
  81. },
  82. geo: {
  83. // type: "map",
  84. map: "anhui",
  85. // 默认设置完地图是固定死的不能拖动
  86. // roam:true,//否开启鼠标缩放和平移漫游。默认不开启。
  87. roam: 1,
  88. //zoom :1,//当前视角的缩放比例。越大比例越大
  89. // center:[108.956239,34.268309],//当前视角的中心点,用经纬度表示108.956239,34.268309
  90. // label:{//地图上显示文字提示信息
  91. // show:true,
  92. // // color:"#ff6600",
  93. // fontSize:10//字体大小
  94. // },
  95. label: {
  96. normal: {
  97. formatter:(params)=>{
  98. console.log(params,'747')
  99. if(params.name=="金寨县"||params.name=="岳西县"||params.name=="旌德县"||params.name=="绩溪县"||params.name=="休宁县"||params.name=="歙县"||params.name=="黟县"||params.name=="祁门县"||params.name=="石台县"||params.name=="青阳县"||params.name=="东至县"||params.name=="黄山区"){
  100. return params.name
  101. }else{
  102. return ''
  103. }
  104. },
  105. show: !0,
  106. fontSize: "11",
  107. color: "#000"
  108. }
  109. },
  110. itemStyle: {
  111. normal: {
  112. areaColor: "#f2d5ad",
  113. // areaColor: "#ff3940",
  114. //shadowBlur: 50,
  115. //shadowColor: 'rgba(0, 0, 0, 0.2)',
  116. borderColor: "rgba(0, 0, 0, 0.2)"
  117. },
  118. emphasis: {
  119. areaColor: "#ff6600",
  120. shadowOffsetX: 0,
  121. shadowOffsetY: 0,
  122. borderWidth: 0
  123. }
  124. }
  125. // itemStyle:{//地图区域的多边形 图形样式。
  126. // areaColor:"#ff6600"//地图区域的颜色。
  127. // }
  128. // label: {
  129. // show: true,
  130. // color: "#1DE9B6",
  131. // },
  132. },
  133. // legend: {
  134. // left: '5%',
  135. // bottom: '5%',
  136. // orient: 'vertical'
  137. // },
  138. series:[
  139. {
  140. name: "殡葬",
  141. type: "map",
  142. geoIndex: 0,
  143. data: this.dataList
  144. }
  145. ]
  146. };
  147. this.chartInstance.setOption(initOption);
  148. this.chartInstance.on("click", async (arg) => {
  149. // arg.name 得到所点击的省份, 这个省份他是中文
  150. });
  151. },
  152. },
  153. };
  154. </script>
  155. <style scoped>
  156. .map {
  157. width: 100%;
  158. height: 100%;
  159. }
  160. .map_chart {
  161. width: 600px;
  162. height: 800px;
  163. margin:0 auto;
  164. }
  165. </style>

  1. <template>
  2. <div class="map">
  3. <div class="map_chart" ref="map_chart"></div>
  4. </div>
  5. </template>
  6. <script>
  7. import axios from "axios";
  8. import {mapData} from '../utils/map'
  9. export default {
  10. name: "Map",
  11. data() {
  12. return {
  13. chartInstance: null,
  14. allData: null,
  15. mapData: {}, // 所获取的省份的地图矢量数据
  16. dataList:[
  17. {name: '庐阳区', value: 101},
  18. {name: '肥东县', value: 101},
  19. {name: '濉溪县', value: 101},
  20. {name: '埇桥区', value: 18},
  21. {name: '萧县', value: 101},
  22. {name: '蚌山区', value: 101},
  23. {name: '颍泉区', value: 101},
  24. {name: '临泉县', value: 101},
  25. {name: '太和县', value: 101},
  26. {name: '舒城县', value: 101},
  27. {name: '当涂县', value: 101},
  28. {name: '南陵县', value: 101},
  29. {name: '宣州区', value: 101},
  30. {name: '郎溪县', value: 101},
  31. {name: '广德市', value: 101},
  32. {name: '泾县', value: 101},
  33. {name: '休宁县', value: 101},
  34. ],
  35. nameStr:'庐阳区肥东县濉溪县埇桥区萧县蚌山区颍泉区临泉县太和县舒城县当涂县南陵县宣州区郎溪县广德市泾县休宁县'
  36. };
  37. },
  38. created() {},
  39. mounted() {
  40. this.initChart();
  41. window.addEventListener("resize", this.screenAdapter);
  42. },
  43. destroyed() {
  44. window.removeEventListener("resize", this.screenAdapter);
  45. },
  46. methods: {
  47. async initChart() {
  48. this.chartInstance = this.$echarts.init(this.$refs.map_chart);
  49. // 获取中国地图的矢量数据
  50. // http://localhost:8999/static/map/china.json
  51. // 由于我们现在获取的地图矢量数据并不是位于KOA2的后台, 所以咱们不能使用this.$http
  52. this.$echarts.registerMap("anhui", mapData);
  53. const initOption = {
  54. // title: {
  55. // text: "▎ 公墓分布",
  56. // left: 20,
  57. // top: 20,
  58. // },
  59. toolbox: {
  60. show: true,
  61. feature: {
  62. saveAsImage: {
  63. show:true
  64. }
  65. }
  66. }, // 提供下载工具
  67. visualMap: {
  68. min: 0,
  69. max: 100000,
  70. left: 26,
  71. bottom: 40,
  72. showLabel: !0,
  73. // text: ["土葬", "智慧殡葬"],
  74. pieces: [{
  75. gte: 1,
  76. lt: 100,
  77. label: "土葬区",
  78. color: "red",
  79. }, {
  80. gte: 100,
  81. lt: 1000,
  82. label: "土葬区",
  83. color: "#ff3990",
  84. },
  85. {
  86. gt: 1000,
  87. lt: 10000,
  88. label: "智慧殡葬",
  89. color: "#f2d5ad"
  90. }],
  91. show: false
  92. },
  93. geo: {
  94. // type: "map",
  95. map: "anhui",
  96. // 默认设置完地图是固定死的不能拖动
  97. // roam:true,//否开启鼠标缩放和平移漫游。默认不开启。
  98. roam: 1,
  99. //zoom :1,//当前视角的缩放比例。越大比例越大
  100. // center:[108.956239,34.268309],//当前视角的中心点,用经纬度表示108.956239,34.268309
  101. // label:{//地图上显示文字提示信息
  102. // show:true,
  103. // // color:"#ff6600",
  104. // fontSize:10//字体大小
  105. // },
  106. label: {
  107. normal: {
  108. formatter:(params)=>{
  109. console.log(params,'747')
  110. // if(params.name=="庐阳区"||params.name=="肥东县"||params.name=="濉溪县"||params.name=="埇桥区"||params.name=="萧县"||params.name=="蚌山区"||params.name=="颍泉区"||params.name=="临泉县"||params.name=="太和县"||params.name=="舒城县"||params.name=="当涂县"||params.name=="南陵县"){
  111. // return params.name
  112. // }else{
  113. // return ''
  114. // }
  115. if(this.nameStr.includes(params.name)){
  116. return params.name
  117. }else{
  118. return ''
  119. }
  120. },
  121. show: !0,
  122. fontSize: "11",
  123. color: "#000"
  124. }
  125. },
  126. itemStyle: {
  127. normal: {
  128. areaColor: "#f2d5ad",
  129. // areaColor: "#ff3940",
  130. //shadowBlur: 50,
  131. //shadowColor: 'rgba(0, 0, 0, 0.2)',
  132. borderColor: "rgba(0, 0, 0, 0.2)"
  133. },
  134. emphasis: {
  135. areaColor: "#ff6600",
  136. shadowOffsetX: 0,
  137. shadowOffsetY: 0,
  138. borderWidth: 0
  139. }
  140. }
  141. // itemStyle:{//地图区域的多边形 图形样式。
  142. // areaColor:"#ff6600"//地图区域的颜色。
  143. // }
  144. // label: {
  145. // show: true,
  146. // color: "#1DE9B6",
  147. // },
  148. },
  149. // legend: {
  150. // left: '5%',
  151. // bottom: '5%',
  152. // orient: 'vertical'
  153. // },
  154. series:[
  155. {
  156. name: "殡葬",
  157. type: "map",
  158. geoIndex: 0,
  159. data: this.dataList
  160. }
  161. ]
  162. };
  163. this.chartInstance.setOption(initOption);
  164. this.chartInstance.on("click", async (arg) => {
  165. // arg.name 得到所点击的省份, 这个省份他是中文
  166. });
  167. },
  168. },
  169. };
  170. </script>
  171. <style scoped>
  172. .map {
  173. width: 100%;
  174. height: 100%;
  175. }
  176. .map_chart {
  177. width: 600px;
  178. height: 800px;
  179. margin:0 auto;
  180. }
  181. </style>

本文转载自: https://blog.csdn.net/qq_38388578/article/details/129589770
版权归原作者 开心就好1314520 所有, 如有侵权,请联系我们删除。

“echarts 地图区域显示不同颜色笔记”的评论:

还没有评论