echarts实现单个省地图 例:内蒙古

在这里插入图片描述
由于项目下载的echarts版本是5.4.0, 所以下载的是内蒙古的json包
json下载地址

选中你要下载的区域,如:
在这里插入图片描述
需要注意的点:

// mounted内使用
 echarts.registerMap('nei', neiJson)
 ”nei“是自定义的,和option内的地图设置的map对应上

在这里插入图片描述
废话不多说,直接上代码

<template>
  <div class="map" id="map"></div>
</template>
<script setup>
import { onMounted, reactive, ref, defineExpose, watch } from 'vue'
import * as echarts from 'echarts'
import neiJson from '@/assets/json/nei.json'

// import 'echarts/map/js/china.js'
let myChart = ''
const option = ref({
  backgroundColor: '#020933',
  title: {
    top: 20,
    text: '内蒙古自治区',
    subtext: '',
    x: 'center',
    textStyle: {
      color: '#ccc',
    },
  },
  visualMap: {
    min: 0,
    max: 1000000,
    right: 100,
    seriesIndex: 1,
    type: 'piecewise',
    bottom: 100,
    textStyle: {
      color: '#FFFF',
    },
    // splitList: [
    //   {
    //     gt: 50000,
    //     color: '#F5222D',
    //     label: '困难人数大于5万人',
    //   }, //大于5万人
    //   {
    //     gte: 30000,
    //     lte: 50000,
    //     color: '#FA541C ',
    //     label: '困难人数3-5万人',
    //   }, //3-5万人
    //   {
    //     gte: 10000,
    //     lte: 30000,
    //     color: '#FA8C16',
    //     label: '困难人数1-3万人',
    //   }, //1-3万人
    //   {
    //     lte: 10000,
    //     color: '#fbe1d6',
    //     label: '困难人数小于1万人',
    //   },
    // ],
  },
  geo: {
    map: 'nei', //地图为刚刚设置的China
    aspectScale: 0.75, //长宽比
    zoom: 1.1,
    roam: false,
    itemStyle: {
      normal: {
        areaColor: '#013C62',
        shadowColor: '#182f68',
        shadowOffsetX: 0,
        shadowOffsetY: 25,
      },
      emphasis: {
        areaColor: '#2AB8FF',
        borderWidth: 0,
        color: 'green',
        label: {
          show: false,
        },
      },
    },
  },
  series: [
    {
      type: 'map',
      roam: true,
      label: {
        normal: {
          show: true,
          textStyle: {
            color: '#fff',
          },
        },
        emphasis: {
          textStyle: {
            color: '#fff',
          },
        },
      },
      itemStyle: {
        normal: {
          borderColor: '#2ab8ff',
          borderWidth: 1.5,
          areaColor: '#12235c',
        },
        emphasis: {
          areaColor: '#2AB8FF',
          borderWidth: 0,
          color: 'green',
        },
      },
      zoom: 1.1,
      roam: false,
      map: 'nei', //使用中国地图
      // data: this.difficultData //热力图数据   不同区域 不同的底色
    },
    {
      type: 'effectScatter',
      coordinateSystem: 'geo',
      showEffectOn: 'render',
      rippleEffect: {
        period: 15,
        scale: 4,
        brushType: 'fill',
      },
      hoverAnimation: true,
      itemStyle: {
        normal: {
          color: '#ffff',
          shadowBlur: 10,
          shadowColor: '#333',
        },
      },
      data: [
        {
          name: '呼和浩特市',
          value: [111.670801, 40.818311],
        },
        {
          name: '包头市',
          value: [109.840405, 40.658168],
        },
        {
          name: '乌海市',
          value: [106.825563, 39.673734],
        },
        {
          name: '赤峰市',
          value: [118.956806, 42.275317],
        },
        {
          name: '通辽市',
          value: [122.263119, 43.617429],
        },
        {
          name: '鄂尔多斯市',
          value: [109.99029, 39.817179],
        },
        {
          name: '呼伦贝尔市',
          value: [119.758168, 49.215333],
        },
        {
          name: '锡林郭勒盟',
          value: [116.090996, 43.944018],
        },
        {
          name: '阿拉善盟',
          value: [105.706422, 38.844814],
        },
      ],
    },
  ],
})
onMounted(() => {
  echarts.registerMap('nei', neiJson)
  mapInit()
})
const mapInit = () => {
  myChart = echarts.init(document.getElementById('map'))
  myChart.clear()
  myChart.setOption(option.value)
}
</script>
<style scoped>
.map {
  /* 父级盒子已经设置宽高 */
  width: 100%;
  height: 100%;
}
</style>
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
实现数值堆叠相加的效果,您可以通过在数据中进行累加的方式来实现。以下是一个示代码: ```html <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>单个堆叠柱状图 - 数值堆叠相加</title> <script src="https://cdn.jsdelivr.net/npm/echarts@5.2.2/dist/echarts.min.js"></script> </head> <body> <div id="chart" style="width: 600px; height: 400px;"></div> <script> // 初始化图表 var chartDom = document.getElementById('chart'); var myChart = echarts.init(chartDom); // 示数据 var data = [ { name: '柱1', series: [10, 20, 30] }, { name: '柱2', series: [15, 25, 35] }, { name: '柱3', series: [30, 40, 50] } ]; // 对数据进行累加 var cumulativeData = []; for (var i = 0; i < data.length; i++) { var sum = 0; for (var j = 0; j < data[i].series.length; j++) { sum += data[i].series[j]; } cumulativeData.push(sum); } // 配置图表选项 var option = { tooltip: { trigger: 'axis', axisPointer: { type: 'shadow' } }, legend: {}, grid: { left: '3%', right: '4%', bottom: '3%', containLabel: true }, xAxis: { type: 'category', data: data.map(item => item.name) }, yAxis: { type: 'value' }, series: [{ name: '堆叠', type: 'bar', stack: 'total', data: cumulativeData }] }; // 使用配置项显示图表 myChart.setOption(option); </script> </body> </html> ``` 在上述代码中,我们首先定义了示数据 `data`,然后对每个柱的数值进行累加得到 `cumulativeData`。接下来,在图表的配置项中,我们使用了堆叠柱状图的方式,并将累加的数据传入 `data` 属性中。最后,使用配置项显示图表。 这样,您就可以在堆叠柱状图中实现数值的堆叠相加效果了。希望对您有所帮助!如有更多问题,请随时提问。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值