echarts 简单绘制地图

效果图

需要导入以下文件

   <script src="~/Scripts/jquery.js"></script>/*Jquery文件*/
    <script src="~/Scripts/echarts.js"></script>/*echarts文件,可从官网下载*/
    <script src="~/Scripts/jiangxi.js"></script>/*省份数据,可从我的网盘中下载*/

以下是完整代码

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <!-- 为 ECharts 准备一个具备大小(宽高)的 DOM -->
    <div id="echartMap" style="width: 1000px;height:1000px;"></div>
    <script src="jquery.min.js"></script>
    <script src="echarts.min.js"></script>
    <script src="jiangxi.js"></script>
    <script type="text/javascript">
        var sData=[
            {name:'南昌市',value:12000000},
            {name:'上饶市',value:12000000},
            {name:'景德镇市',value:12000000},
            {name:'九江市',value:12000000},
            {name:'宜春市',value:12000000},
            {name:'抚州市',value:12000000},
            {name:'吉安市',value:12000000},
            {name:'赣州市',value:12000000},
            {name:'新余市',value:12000000},
            {name:'萍乡市',value:12000000},
            {name:'鹰潭市',value:12000000},
        ]
       // 基于准备好的dom,初始化echarts实例
       var myChart = echarts.init(document.getElementById('echartMap'));
       var option = {
           tooltip: {
               show: true,
               trigger: 'item',
               triggerOn: 'click',
               formatter: "名称:{b}<br />坐标:{c}"
           },
           series: [{
                   name: "江西省分布",
                   type: 'custom',//配置显示方式为用户自定义
                   legendHoverLink:true,
                   coordinateSystem: 'geo',
                //    itemStyle: {
                //        normal: {
                //            color: '#46bee9'
                //        },
                //        label:{show:true}
                //    },
                   data: sData //    coldCar
               }
           ],
           legend: {
            //    type: "plain",
               show: true,
               orient: 'vertical',
               x: 'middle',
               y: 'left',
               data: [
                   {
                       name: "分布",
                       icon: "circle",
                       textStyle: {
                           color: "#a9d6fa"
                       }
                   }
               ]
           },
           geo: {//引入江西省的地图
               map: '江西',
               label: {
                   show:true,
                   color:'#000',
                   fontSize:18,
                   emphasis: {
                       show: true,
                       color:'#000',
                   }
               },
               roam: true,
               zoom: 1,
               zlevel:0,
               itemStyle: {
                   normal: {
                       borderColor: '#fff'
                   },
                   emphasis: {
                        borderColor: '#1890ff',
                        shadowColor: 'rgba(0, 0, 0, 0.5)',
                        shadowBlur: 5,
                        shadowOffsetX: 5
                   }
               },
               regions: [//对不同的区块进行着色
                   {
                       name: '上饶市',
                       itemStyle: {
                           normal: {
                               areaColor: '#5CD89E'
                           },
                           emphasis: {
                            areaColor: '#5CD89E',
                            }
                       }
                   }, {
                       name: '景德镇市',
                       itemStyle: {
                           normal: {
                               areaColor: '#FCCF73'
                           },
                           emphasis: {
                            areaColor: '#FCCF73',
                            }
                       }
                   }, {
                       name: '鹰潭市',
                       itemStyle: {
                           normal: {
                               areaColor: '#81A1FD'
                           },
                           emphasis: {
                            areaColor: '#81A1FD',
                            }
                       }
                   }, {
                       name: '南昌市',
                       itemStyle: {
                           normal: {
                               areaColor: '#FD898D'
                           },
                           emphasis: {
                            areaColor: '#FD898D',
                            }
                       }
                   }, {
                       name: '九江市',
                       itemStyle: {
                           normal: {
                               areaColor: '#FCCF73'
                           },
                           emphasis: {
                            areaColor: '#FCCF73',
                            }
                       }
                   }, {
                       name: '宜春市',
                       itemStyle: {
                           normal: {
                               areaColor: '#81A1FD'
                           },
                           emphasis: {
                            areaColor: '#81A1FD',
                            }
                       }
                   }, {
                       name: '抚州市',
                       itemStyle: {
                           normal: {
                               areaColor: '#FCCF73'
                           },
                           emphasis: {
                            areaColor: '#FCCF73',
                            }
                       }
                   }, {
                       name: '新余市',
                       itemStyle: {
                           normal: {
                               areaColor: '#5CD89E'
                           },
                           emphasis: {
                            areaColor: '#5CD89E',
                            }
                       }
                   }, {
                       name: '萍乡市',
                       itemStyle: {
                           normal: {
                               areaColor: '#FCCF73'
                           },
                           emphasis: {
                            areaColor: '#FCCF73',
                            }
                       }
                   }, {
                       name: '吉安市',
                       itemStyle: {
                           normal: {
                               areaColor: '#FD898B'
                           },
                           emphasis: {
                            areaColor: '#FD898B',
                            }
                       }
                   }, {
                       name: '赣州市',
                       itemStyle: {
                           normal: {
                               areaColor: '#81A1FD'
                           },
                           emphasis: {
                            areaColor: '#81A1FD',
                            }
                       }
                   }
               ]
           
            }
       };
       myChart.setOption(option);
       myChart.on('click',function(params){
           if(params.componentType=='geo'){
               if(params.name='上饶市'){
                   console.log('上饶市');
               }
           }

       })
    </script>
</body>

</html>

注:关于文字不居中,地图上显示名称的位置为其省会的坐标位置。在导入的地图数据中,直接搜索相关地区名字,可以看到经纬度坐标。也就是只需要改变cp下的经纬度就可以改变图上文字位置。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值