中国地图(两部搞定)

1  map.vue

<template>
  <div class="centent" ref="echarts"></div>
</template>

<script>
// 引入echarts
import echarts from "echarts";
// 引入地图
import "echarts/lib/chart/map";
// 引入js
import "echarts/map/js/china.js";
export default {
  components: {},
  data() {
    // 这里存放数据
    return {};
  },

  mounted() {
    this.init();
  },
  // 方法集合
  methods: {
    init() {
      let myChart = echarts.init(this.$refs.echarts);
      let option = {
        tooltip: {
          // 鼠标移到图里面的浮动提示框
          formatter(params) {
            let htmlStr = `
                          <div style='font-size:18px;'> ${params.name}</div>
                        `;
            return htmlStr;
          },
        },
        // geo配置详解: https://echarts.baidu.com/option.html#geo
        geo: {
          map: "china",
          show: true,
          roam: true,
          top: 0,
          label: {
            emphasis: {
              show: false,
            },
          },
          // 地图的背景色
          itemStyle: {
            normal: {
              areaColor: "#091632",
              borderColor: "#9adcfa",
              shadowColor: "#09184F",
              shadowBlur: 20,
            },
          },
        },
        series: [
          // 地图部分
          {
            type: "map",
            map: "china",
            geoIndex: 1,
            aspectScale: 0.75, // 长宽比
            showLegendSymbol: true, // 存在legend时显示
            top: 0,
            label: {
              normal: {
                show: false,
              },
              emphasis: {
                show: false,
                textStyle: {
                  color: "#fff",
                },
              },
            },
            //是否开启鼠标缩放和平移漫游
            roam: false,
            //默认样式
            itemStyle: {
              normal: {
                areaColor: "#031525",
                borderColor: "#3B5077",
                borderWidth: 1,
              },
              emphasis: {
                areaColor: "#0f2c70",
              },
            },
            data: [
              {
                name: "黑龙江",
                //自定义省的颜色
                itemStyle: {
                  normal: {
                    areaColor: "#F50508",
                    borderColor: "#1773c3", // 区域边框
                    shadowColor: "#1773c3", // 阴影
                    shadowBlur: 20,
                  },
                },
              },
            ],
            zlevel: 0,
          },
          // 气泡
          {
            type: "effectScatter",
            coordinateSystem: "geo",
            //要有对应的经纬度才显示,先经度再维度
            data: [{ name: "长春", value: [125.35, 43.88] }],
            showEffectOn: "render",
            rippleEffect: {
              scale: 4, // 波纹的最大缩放比例
              brushType: "stroke",
            },
            hoverAnimation: true,
            label: {
              normal: {
                show: true,
                formatter: "{b}",
                position: "right",
                fontWeight: 500,
                fontSize: 14,
              },
            },
            itemStyle: {
              normal: {
                color: "#32cd32",
                shadowBlur: 10,
                shadowColor: "#333",
              },
            },
            emphasis: {
              itemStyle: {
                color: "#f4e925", // 高亮颜色
              },
            },
            zlevel: 1,
          },
        ],
      };
      myChart.setOption(option);
      window.addEventListener("resize", function () {
        myChart.resize();
      });
    },
  },
};
</script>
<style lang="scss" scoped>
.centent {
  width: 1000px;
  height: 1000px;
  margin-top: 100px;
}
</style>

2main.js

import * as echarts from "echarts";
Vue.prototype.$echarts = echarts; // 将echarts引入与到vue的原型中,方便使用

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值