ECharts 实现世界地图

效果图

在这里插入图片描述

源代码(仅供参考)

<template>
  <div class="echarts">
    <div
      class="className"
      id="id"
      style="width: 100%; height: 450px"
      ref="myEchart"
    ></div>
  </div>
</template>
<script lang="ts">
import Vue from "vue";
import echarts from "echarts";
// 引用世界地图js 
import "@/js/world_new.js";
import Component from "vue-class-component";

@Component
export default class World extends Vue {
  name = "echarts";

  initChart() {
    let myChart = echarts.init(this.$refs.myEchart);
    window.onresize = echarts.init(this.$refs.myEchart).resize;
    // 把配置和数据放这里
    myChart.setOption({
      backgroundColor: "#02AFDB",
      title: {
        left: "40%",
        top: "0px",
        textStyle: {
          color: "#fff",
          opacity: 0.7,
        },
      },
      dataRange: {
        show: false,
        min: 0,
        max: 1000000,
        text: ["High", "Low"],
        realtime: true,
        calculable: true,
        color: ["orangered", "yellow", "lightskyblue"],
      },
      tooltip: {
        formatter: function (params: any, ticket: any, callback: any) {
          // params.seriesName + "<br />" + params.name + ":" + params.value
          return params.name + ":" + params.value;
        }, //数据格式化
      },
      geo: {
        map: "world",
        label: {
          emphasis: {
            show: false,
          },
        },
        roam: false,
        silent: true,
        itemStyle: {
          normal: {
            areaColor: "#37376e",
            borderColor: "#000",
          },
          emphasis: {
            areaColor: "#2a333d",
          },
        },
      },
      series: [
        {
          type: "map",
          mapType: "world",
          // zoom: 1.2,
          mapLocation: {
            y: 100,
          },
          
          nameMap //nameMap映射
          data //数据国家名字
          
          symbolSize: 12,
          label: {
            normal: {
              show: false,
            },
            emphasis: {
              show: false,
            },
          },
          itemStyle: {
            emphasis: {
              borderColor: "#fff",
              borderWidth: 1,
            },
          },
        },
      ],
    });
  }

  mounted() {
    this.initChart();
  }
}
</script>

重要

1,需要下载世界地图所需要的js文件 下载链接
2,data 数据国家名字 && nameMap 映射可参考这里

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值