vue项目中使用echarts - china.js绘制地图,并且回调所点击的省份

项目需求:绘制一幅中国省份地图,点击地图中的省份,更改其它图表的数据。

地图交互效果如下图:

 

实现代码如下:

import { mapGetters } from 'vuex'
import '../../../../node_modules/echarts/map/js/china.js' // 引入中国地图数据
const echarts = require('echarts')

export default {
  name: 'Dashboard',
  data() {
    return {
      myChinaMap: {}
    }
  },
  computed: {
    ...mapGetters([
      'name'
    ])
  },
  mounted() {
    const _this = this
    this.$nextTick(() => {
      _this.myChinaMap = echarts.init(this.$refs.mapContainer)

      _this.myChinaMap.on('click', function(param) {
        console.log(param)
      })

      _this.myChinaMap.setOption({ // 进行相关配置
        backgroundColor: '#fff',
        tooltip: {}, // 鼠标移到图里面的浮动提示框
        dataRange: {
          show: false,
          min: 0,
          max: 1000,
          text: ['High', 'Low'],
          realtime: true,
          calculable: true,
          color: ['orangered', 'yellow', 'lightskyblue']
        },
        geo: { // 这个是重点配置区
          map: 'china', // 表示中国地图
          roam: true,
          selectedMode: 'single',
          label: {
            normal: {
              show: true, // 是否显示对应地名
              textStyle: {
                color: 'rgba(0,0,0,0.4)'
              }
            }
          },
          itemStyle: {
            normal: {
              borderColor: 'rgba(0, 0, 0, 0.2)'
            },
            emphasis: {
              areaColor: null,
              shadowOffsetX: 0,
              shadowOffsetY: 0,
              shadowBlur: 20,
              borderWidth: 0,
              shadowColor: 'rgba(0, 0, 0, 0.5)'
            }
          }
        }
    })
}

 

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值