HTML地图上绘制点,echarts在地图上绘制散点图(任意点)

var dom = document.getElementById("container");var myChart =echarts.init(dom);

option= null;//散点在地图上的坐标

var geoCoordMap ={"国家级基地1": [94.12, 39.66],"国家级基地2": [97.20, 39.55],"国家级基地3": [95.28, 40.29],"省级基地1": [98.36, 40.19],"省级基地2": [97.88, 39.49],"省级基地3": [95.77, 40.59],"市级基地1": [102.66, 38.89],"市级基地2": [101.23, 37.79],"市级基地3": [99.40, 39.69]

};//将坐标与值对应并反映在地图上

var convertData = function(data) {var res =[];for (var i = 0; i < data.length; i++) {var geoCoord =geoCoordMap[data[i].name];if(geoCoord) {

res.push({

name: data[i].name,

value: geoCoord.concat(data[i].value)

});

}

}returnres;

};

option={

tooltip: {

trigger:‘item‘,

formatter:function(params) {returnparams.name;

}

},

visualMap: {

type:‘piecewise‘,

textStyle: {

color:‘#fff‘},

pieces: [

{min:300, label: ‘国家级基地‘, color: ‘#e3bf4c‘},

{min:200, max: 300, label: ‘省级基地‘, color: ‘#be4f51‘},

{min:100, max: 200, label: ‘市级基地‘, color: ‘#60c2cc‘}

],

color: [‘#e3bf4c‘, ‘#be4f51‘, ‘#60c2cc‘]

},

geo: {

map:‘甘肃‘,

label: {

emphasis: {

show:false}

},

itemStyle: {

normal: {

areaColor:‘#323c48‘,

borderColor:‘#111‘},

emphasis: {

areaColor:‘#2a333d‘}

}

},

series: [

{

type:‘effectScatter‘,

coordinateSystem:‘geo‘,

data: convertData([

{name:"国家级基地1", value: 110},

{name:"国家级基地2", value: 110},

{name:"国家级基地3", value: 110},

{name:"省级基地1", value: 210},

{name:"省级基地2", value: 210},

{name:"省级基地3", value: 210},

{name:"市级基地1", value: 310},

{name:"市级基地2", value: 310},

{name:"市级基地3", value: 310}

]),

symbolSize:12,

label: {

normal: {

show:false},

emphasis: {

show:false}

},

itemStyle: {

emphasis: {

borderColor:‘#fff‘,

borderWidth:1}

}

}

]

};if (option && typeof option === "object") {

myChart.setOption(option,true);

}

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在echarts地图上显示,需要在series(系列列表配置)中添加两个表配置,通过修改type值,决定表类型(地图)。具体步骤如下: 1.在html文件中引入echarts.js文件。 2.在html文件中创建一个div元素,用于显示echarts地图。 3.在JavaScript文件中定义一个echarts实例,并将其与div元素关联。 4.在JavaScript文件中定义一个option对象,用于配置echarts地图。 5.在option对象中添加series(系列列表配置)配置项,用于添加地图。 6.在series配置项中添加两个表配置,一个用于,一个用于地图。 7.在配置中,设置type为scatter,然后设置data为的数据。 8.在地图配置中,设置type为map,然后设置mapType为地图类型,设置data为地图的数据。 9.最后,调用echarts实例的setOption方法,将option对象传递给它,以显示echarts地图。 下面是一个示例代码,用于在echarts地图上显示: ```html <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>ECharts</title> <script src="https://cdn.jsdelivr.net/npm/echarts@5.2.1/dist/echarts.min.js"></script> </head> <body> <div id="main" style="width: 600px;height:400px;"></div> <script> var myChart = echarts.init(document.getElementById('main')); var option = { series: [ { type: 'scatter', data: [[10, 20], [20, 30], [30, 40], [40, 50]] }, { type: 'map', mapType: 'china', data: [ {name: '北京', value: Math.round(Math.random() * 1000)}, {name: '天津', value: Math.round(Math.random() * 1000)}, {name: '上海', value: Math.round(Math.random() * 1000)}, {name: '重庆', value: Math.round(Math.random() * 1000)}, {name: '河北', value: Math.round(Math.random() * 1000)}, {name: '河南', value: Math.round(Math.random() * 1000)}, {name: '云南', value: Math.round(Math.random() * 1000)}, {name: '辽宁', value: Math.round(Math.random() * 1000)}, {name: '黑龙江', value: Math.round(Math.random() * 1000)}, {name: '湖南', value: Math.round(Math.random() * 1000)}, {name: '安徽', value: Math.round(Math.random() * 1000)}, {name: '山东', value: Math.round(Math.random() * 1000)}, {name: '新疆', value: Math.round(Math.random() * 1000)}, {name: '江苏', value: Math.round(Math.random() * 1000)}, {name: '浙江', value: Math.round(Math.random() * 1000)}, {name: '江西', value: Math.round(Math.random() * 1000)}, {name: '湖北', value: Math.round(Math.random() * 1000)}, {name: '广西', value: Math.round(Math.random() * 1000)}, {name: '甘肃', value: Math.round(Math.random() * 1000)}, {name: '山西', value: Math.round(Math.random() * 1000)}, {name: '内蒙古', value: Math.round(Math.random() * 1000)}, {name: '陕西', value: Math.round(Math.random() * 1000)}, {name: '吉林', value: Math.round(Math.random() * 1000)}, {name: '福建', value: Math.round(Math.random() * 1000)}, {name: '贵州', value: Math.round(Math.random() * 1000)}, {name: '广东', value: Math.round(Math.random() * 1000)}, {name: '青海', value: Math.round(Math.random() * 1000)}, {name: '西藏', value: Math.round(Math.random() * 1000)}, {name: '四川', value: Math.round(Math.random() * 1000)}, {name: '宁夏', value: Math.round(Math.random() * 1000)}, {name: '海南', value: Math.round(Math.random() * 1000)}, {name: '台湾', value: Math.round(Math.random() * 1000)}, {name: '香港', value: Math.round(Math.random() * 1000)}, {name: '澳门', value: Math.round(Math.random() * 1000)} ] } ] }; myChart.setOption(option); </script> </body> </html> ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值