首页 前端知识 echarts地图根据数值范围显示不同的颜色

echarts地图根据数值范围显示不同的颜色

2024-04-29 11:04:33 前端知识 前端哥 842 849 我要收藏

效果展示在这里插入图片描述

代码

<template>
  <div>
    <div ref="main" id="main"></div>
  </div>
</template>
 
<script>
import * as echarts from "echarts";
import chinaMap from "@/assets/zhej.json";
export default {
  data() {
    return {
      map: null,
      //复制 name与json文件里的name对应后就可以显示value
      seriesData: [
        { name: "淳安县", value: 70},
        { name: "临安区", value: 60 },
        { name: "建德市", value: 80 },
        { name: "桐庐县", value: 90 },
        { name: "富阳区", value: 68 },
        { name: "余杭区", value: 65},
        { name: "萧山区", value: 55 },
        { name: "钱塘新区", value: 60 },
        { name: "主城区", value: 61 },
         { name: "西湖区", value: 10 },
      ],
    };
  },
  mounted() {
    this.init();
  },
  methods: {
    //初始化
    init() {
      this.map = echarts.init(this.$refs.main);
      echarts.registerMap("chinaMap", chinaMap);
      var option = {
        geo: {
          map: "chinaMap",
          itemStyle: {
            borderColor: "rgba(196,223,255,1)",
            borderWidth: 2,
            shadowColor: "rgba(196,223,255,.8)",
            shadowBlur: 20,
            shadowOffsetX: 4,
            shadowOffsetY: 4,
          },
        },
        visualMap: {
          type: "piecewise",
          splitNumber: 3,
          min:60 ,
          max: 89,
          align: "left",
          right: 20,
          bottom: 20,
          itemWidth: 60,
          itemHeight: 20,
          itemGap: 5,
          // itemSymbol: 'circle',
          orient: "vertical",
          //区域颜色
          color: ["#0044ff","#00b1ff","#00eaf3"],
          //区域颜色范范围
          pieces: [
            {min: 60, max: 69},
            {min: 70, max: 79},
            {min: 80, max: 89}
          ],
          textStyle: {
            color: "#fff",
            fontSize: 14
          },
        },
        series: [
          {
            map: "chinaMap",
            type: "map",
            label: {
              normal: {
                color: "rgba(255,255,255,1)",
                show: true,
                color: "#fff",
                textShadowColor: "rgba(0,0,0,0.5)",
                textShadowBlur: 4,
                textShadowOffsetX: 0,
                textShadowOffsetY: 1,
                fontWeight: "normal",
                formatter(params) {
                  // console.log(params)
                  //seriesData 里面没有的区会显示NaN demo写的不严谨 无所谓了   初始化显示名称
                  return params.name+params.value
                },
              },
            },
            itemStyle: {
              borderColor: "rgba(196,223,255,1)",
              borderWidth: 2,
              areaColor: {
                type: "linear",
                x: 0,
                y: 0,
                x2: 0,
                y2: 1,
                colorStops: [
                  {
                    offset: 0,
                    color: "rgba(102,172,191,1)",
                  },
                  {
                    offset: 1,
                    color: "rgba(21,118,145,1)",
                  },
                ],
                global: false,
              },
            },
            zlevel: 1,
            data:this.seriesData
          },
        ],
      };
      this.map.setOption(option);
    },
  },
};
</script>
 
<style scoped>
#main {
  width: 800px;
  height: 600px;
  margin: 0 auto;
  background: red;
}
</style>
转载请注明出处或者链接地址:https://www.qianduange.cn//article/6024.html
标签
评论
发布的文章

qt JSON和字符串相互转换

2024-05-05 12:05:04

nlohmann::json从入门到精通

2024-05-05 12:05:00

Android-第十节JSON讲解

2024-05-05 12:05:35

FastJson 框架详解

2024-05-05 12:05:31

MySql操作JSON

2024-05-05 12:05:31

大家推荐的文章
会员中心 联系我 留言建议 回顶部
复制成功!