教你用ECharts轻松绘制地图图表:10个实用案例解析与实战技巧

2026-10-10 0 阅读

案例一:中国省市区级地图

案例简介

中国省市区级地图是展示中国地理分布和行政区划的一种常见方式。使用ECharts可以轻松实现这一功能。

实战技巧

  1. 使用ECharts内置的echarts/map/js/china.js地图数据。
  2. 配置series中的type为map,并设置mapType为china。
  3. 可根据需求添加label、itemStyle等属性,自定义地图样式。

代码示例

var myChart = echarts.init(document.getElementById('main'));

var option = {
    series: [{
        type: 'map',
        mapType: 'china',
        label: {
            show: true
        },
        itemStyle: {
            areaColor: '#323c48',
            borderColor: '#111'
        }
    }]
};

myChart.setOption(option);

案例二:世界地图

案例简介

世界地图可以展示全球各国地理位置和分布情况。

实战技巧

  1. 使用ECharts内置的echarts/map/js/world.js地图数据。
  2. 配置series中的type为map,并设置mapType为world。
  3. 可根据需求添加label、itemStyle等属性,自定义地图样式。

代码示例

var myChart = echarts.init(document.getElementById('main'));

var option = {
    series: [{
        type: 'map',
        mapType: 'world',
        label: {
            show: true
        },
        itemStyle: {
            areaColor: '#323c48',
            borderColor: '#111'
        }
    }]
};

myChart.setOption(option);

案例三:美国州地图

案例简介

美国州地图可以展示美国各州地理位置和分布情况。

实战技巧

  1. 使用ECharts内置的echarts/map/js/us.js地图数据。
  2. 配置series中的type为map,并设置mapType为us。
  3. 可根据需求添加label、itemStyle等属性,自定义地图样式。

代码示例

var myChart = echarts.init(document.getElementById('main'));

var option = {
    series: [{
        type: 'map',
        mapType: 'us',
        label: {
            show: true
        },
        itemStyle: {
            areaColor: '#323c48',
            borderColor: '#111'
        }
    }]
};

myChart.setOption(option);

案例四:中国城市地图

案例简介

中国城市地图可以展示中国各城市地理位置和分布情况。

实战技巧

  1. 使用ECharts内置的echarts/map/js/china-provinces.js地图数据。
  2. 配置series中的type为map,并设置mapType为china-provinces。
  3. 可根据需求添加label、itemStyle等属性,自定义地图样式。

代码示例

var myChart = echarts.init(document.getElementById('main'));

var option = {
    series: [{
        type: 'map',
        mapType: 'china-provinces',
        label: {
            show: true
        },
        itemStyle: {
            areaColor: '#323c48',
            borderColor: '#111'
        }
    }]
};

myChart.setOption(option);

案例五:中国地铁线路图

案例简介

中国地铁线路图可以展示中国各大城市地铁线路分布情况。

实战技巧

  1. 使用自定义地图数据。
  2. 配置series中的type为lines和effectScatter。
  3. 可根据需求添加label、itemStyle等属性,自定义地图样式。

代码示例

var myChart = echarts.init(document.getElementById('main'));

var option = {
    series: [{
        type: 'lines',
        coordinateSystem: 'geo',
        data: [
            // 线路数据
        ],
        effect: {
            show: true,
            period: 6,
            trailLength: 0.7,
            color: '#fff',
            symbolSize: 3
        },
        lineStyle: {
            color: '#fff',
            width: 1,
            opacity: 0.6,
            curveness: 0.2
        }
    }, {
        type: 'effectScatter',
        coordinateSystem: 'geo',
        data: [
            // 节点数据
        ],
        symbolSize: 6,
        rippleEffect: {
            brushType: 'stroke'
        },
        label: {
            normal: {
                formatter: '{b}',
                position: 'right',
                show: true
            }
        },
        itemStyle: {
            color: '#f4e925',
            shadowBlur: 10,
            shadowColor: '#333'
        }
    }]
};

myChart.setOption(option);

案例六:中国行政区划图

案例简介

中国行政区划图可以展示中国各级行政区划的地理位置和分布情况。

实战技巧

  1. 使用自定义地图数据。
  2. 配置series中的type为map。
  3. 可根据需求添加label、itemStyle等属性,自定义地图样式。

代码示例

var myChart = echarts.init(document.getElementById('main'));

var option = {
    series: [{
        type: 'map',
        mapType: 'china-provinces',
        label: {
            show: true
        },
        itemStyle: {
            areaColor: '#323c48',
            borderColor: '#111'
        }
    }]
};

myChart.setOption(option);

案例七:美国州级地图

案例简介

美国州级地图可以展示美国各州地理位置和分布情况。

实战技巧

  1. 使用ECharts内置的echarts/map/js/us.js地图数据。
  2. 配置series中的type为map,并设置mapType为us。
  3. 可根据需求添加label、itemStyle等属性,自定义地图样式。

代码示例

var myChart = echarts.init(document.getElementById('main'));

var option = {
    series: [{
        type: 'map',
        mapType: 'us',
        label: {
            show: true
        },
        itemStyle: {
            areaColor: '#323c48',
            borderColor: '#111'
        }
    }]
};

myChart.setOption(option);

案例八:中国城市地铁线路图

案例简介

中国城市地铁线路图可以展示中国各大城市地铁线路分布情况。

实战技巧

  1. 使用自定义地图数据。
  2. 配置series中的type为lines和effectScatter。
  3. 可根据需求添加label、itemStyle等属性,自定义地图样式。

代码示例

var myChart = echarts.init(document.getElementById('main'));

var option = {
    series: [{
        type: 'lines',
        coordinateSystem: 'geo',
        data: [
            // 线路数据
        ],
        effect: {
            show: true,
            period: 6,
            trailLength: 0.7,
            color: '#fff',
            symbolSize: 3
        },
        lineStyle: {
            color: '#fff',
            width: 1,
            opacity: 0.6,
            curveness: 0.2
        }
    }, {
        type: 'effectScatter',
        coordinateSystem: 'geo',
        data: [
            // 节点数据
        ],
        symbolSize: 6,
        rippleEffect: {
            brushType: 'stroke'
        },
        label: {
            normal: {
                formatter: '{b}',
                position: 'right',
                show: true
            }
        },
        itemStyle: {
            color: '#f4e925',
            shadowBlur: 10,
            shadowColor: '#333'
        }
    }]
};

myChart.setOption(option);

案例九:中国行政区划图

案例简介

中国行政区划图可以展示中国各级行政区划的地理位置和分布情况。

实战技巧

  1. 使用自定义地图数据。
  2. 配置series中的type为map。
  3. 可根据需求添加label、itemStyle等属性,自定义地图样式。

代码示例

var myChart = echarts.init(document.getElementById('main'));

var option = {
    series: [{
        type: 'map',
        mapType: 'china-provinces',
        label: {
            show: true
        },
        itemStyle: {
            areaColor: '#323c48',
            borderColor: '#111'
        }
    }]
};

myChart.setOption(option);

案例十:世界地图

案例简介

世界地图可以展示全球各国地理位置和分布情况。

实战技巧

  1. 使用ECharts内置的echarts/map/js/world.js地图数据。
  2. 配置series中的type为map,并设置mapType为world。
  3. 可根据需求添加label、itemStyle等属性,自定义地图样式。

代码示例

var myChart = echarts.init(document.getElementById('main'));

var option = {
    series: [{
        type: 'map',
        mapType: 'world',
        label: {
            show: true
        },
        itemStyle: {
            areaColor: '#323c48',
            borderColor: '#111'
        }
    }]
};

myChart.setOption(option);
分享到: