通过echarts展示不同省、市、区地图 vue3写法

1.通过阿里的datav:https://datav.aliyun.com/portal/school/atlas/area_generator#8.82/119.751701/28.967880
或者 https://hxkj.vip/demo/echartsMap/ 下载对应边界数据的.geoJson文件数据

2.引入

const uploadedDataURL = '/wyx.geoJson'

注意:
vue-cli3.0用axios加载本地json数据需要先将静态文件放在public文件夹中,把路径换成本地服务地址 + public + 文件名,不然通过axios获取数据404
在这里插入图片描述
获取到的数据结构如下图:
在这里插入图片描述
效果图:
在这里插入图片描述

完整代码如下图:

<template>
  <div ref="about" id="main" class="about" style="height:100vh;width:100%;">
  </div>
</template>
<script setup>
import * as echarts from 'echarts'
import { onMounted, ref } from 'vue'
import axios from 'axios'
const uploadedDataURL = '/wyx.geoJson'
const about = ref(null)
// console.log(about)
const getChart = () => {
  let data = []
  axios.get(uploadedDataURL).then(json => {
    console.log(json)
    const myChart = echarts.init(about.value)
    echarts.registerMap('金华', json.data)
    data = json.data.features.map((item) => { // 显示窗口的数据转换
      return {
        value: (Math.random() * 1000).toFixed(2),
        name: item.properties.name
      }
    })

    myChart.setOption({
      backgroundColor: '#404a59', // 背景
      tooltip: { // 窗口外框
        backgroundColor: 'rgba(0,0,0,0)',
        trigger: 'item'
      },
      title: {
        show: true,
        x: 'center',
        text: '金华市行政区域图',
        textStyle: {
          color: '#2980b9',
          fontSize: 16
        }
      },
      legend: {
        show: false
      },
      series: [{
        tooltip: { // 显示的窗口
          trigger: 'item'

        },
        name: '',
        type: 'map',
        map: '金华', // 自定义扩展图表类型
        zoom: 0.65, // 缩放
        showLegendSymbol: true,
        label: { // 文字
          show: true,
          color: '#fff',
          fontSize: 15,
          formatter: (params) => {
            return params.name
          }
        },
        itemStyle: { // 地图样式

          borderColor: 'rgba(147, 235, 248, 1)',
          borderWidth: 1,
          areaColor: {
            type: 'radial',
            x: 0.5,
            y: 0.5,
            r: 0.8,
            colorStops: [{
              offset: 0,
              color: 'rgba(147, 235, 248, 0)' // 0% 处的颜色
            }, {
              offset: 1,
              color: 'rgba(147, 235, 248, .2)' // 100% 处的颜色
            }],
            globalCoord: false // 缺省为 false
          },
          shadowColor: 'rgba(128, 217, 248, 1)',
          // shadowColor: 'rgba(255, 255, 255, 1)',
          shadowOffsetX: -2,
          shadowOffsetY: 2,
          shadowBlur: 10

        },
        emphasis: { // 鼠标移入动态的时候显示的默认样式
          itemStyle: {
            areaColor: '#FFD181',
            borderColor: '#404a59',
            borderWidth: 1
          }
        },
        layoutCenter: ['45%', '45%'],
        layoutSize: '100%',
        markPoint: {
          symbol: 'none'
        },
        data: data
      }]
    }
    )
  })
}
onMounted(() => {
  getChart()
})
</script>

  • 7
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
可以使用Vue3和Echarts展示山东地图。首先需要引入Echarts和山东地图的js文件,然后在Vue3中创建一个Echarts实例并设置地图的配置项和数据。具体步骤如下: 1. 在Vue3项目中安装Echarts和山东地图的js文件: ``` npm install echarts --save npm install echarts/map/js/province/shandong.js --save ``` 2. 在Vue3组件中引入Echarts和山东地图的js文件: ``` import echarts from 'echarts' import 'echarts/map/js/province/shandong.js' ``` 3. 在Vue3组件中创建一个Echarts实例并设置地图的配置项和数据: ``` <template> <div ref="chart" style="width: 100%; height: 500px;"></div> </template> <script> export default { mounted() { const chart = echarts.init(this.$refs.chart) chart.setOption({ tooltip: { trigger: 'item', formatter: '{b}' }, series: [ { type: 'map', map: '山东', label: { show: true }, itemStyle: { normal: { borderColor: '#fff', borderWidth: 1 }, emphasis: { areaColor: '#f2d5ad', label: { show: true } } }, data: [ { name: '济南', value: 100 }, { name: '青岛', value: 50 }, { name: '淄博', value: 30 }, { name: '枣庄', value: 20 }, { name: '东营', value: 10 }, { name: '烟台', value: 80 }, { name: '潍坊', value: 60 }, { name: '济宁', value: 40 }, { name: '泰安', value: 30 }, { name: '威海', value: 20 }, { name: '日照', value: 10 }, { name: '莱芜', value: 5 }, { name: '临沂', value: 70 }, { name: '德州', value: 50 }, { name: '聊城', value: 30 }, { name: '滨州', value: 20 }, { name: '菏泽', value: 10 } ] } ] }) } } </script> ``` 以上就是使用Vue3和Echarts展示山东地图的基本步骤。如果需要添加点击份事件,可以参考引用中的代码实现。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值