在数据可视化领域,ECharts 是一款非常受欢迎的 JavaScript 库,它可以帮助开发者轻松地创建丰富的交互式图表。其中,地图图表因其直观的地理信息展示方式而备受青睐。对于新手来说,掌握 ECharts 地图图表的制作并不难,下面我将通过 30 个实用案例,带你轻松入门 ECharts 地图图表的制作。

1. 基础地图图表

案例一:中国地图

// 引入 ECharts 主模块
var myChart = echarts.init(document.getElementById('main'));

// 指定图表的配置项和数据
var option = {
    title: {
        text: '中国地图'
    },
    tooltip: {},
    visualMap: {
        min: 0,
        max: 100,
        left: 'left',
        top: 'bottom',
        text: ['高','低'],           // 文本,默认为数值文本
        calculable: true
    },
    series: [
        {
            name: '中国地图',
            type: 'map',
            mapType: 'china',
            roam: true,
            label: {
                normal: {
                    show: true
                },
                emphasis: {
                    show: true
                }
            },
            data: [
                {name: '北京',value: Math.round(Math.random() * 1000)},
                {name: '上海',value: Math.round(Math.random() * 1000)},
                // ... 其他省份数据
            ]
        }
    ]
};

// 使用刚指定的配置项和数据显示图表。
myChart.setOption(option);

案例二:世界地图

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

var option = {
    title: {
        text: '世界地图'
    },
    tooltip: {},
    visualMap: {
        min: 0,
        max: 100,
        left: 'left',
        top: 'bottom',
        text: ['高','低'],
        calculable: true
    },
    series: [
        {
            name: '世界地图',
            type: 'map',
            mapType: 'world',
            roam: true,
            label: {
                normal: {
                    show: true
                },
                emphasis: {
                    show: true
                }
            },
            data: [
                {name: '中国',value: Math.round(Math.random() * 1000)},
                // ... 其他国家数据
            ]
        }
    ]
};

myChart.setOption(option);

2. 高级地图图表

案例三:省份热力图

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

var option = {
    title: {
        text: '省份热力图'
    },
    tooltip: {},
    visualMap: {
        min: 0,
        max: 100,
        left: 'left',
        top: 'bottom',
        text: ['高','低'],
        calculable: true
    },
    series: [
        {
            name: '省份热力图',
            type: 'map',
            mapType: 'china',
            roam: true,
            label: {
                normal: {
                    show: true
                },
                emphasis: {
                    show: true
                }
            },
            data: [
                {name: '北京',value: Math.round(Math.random() * 1000)},
                {name: '上海',value: Math.round(Math.random() * 1000)},
                // ... 其他省份数据
            ]
        }
    ]
};

myChart.setOption(option);

案例四:多层级地图

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

var option = {
    title: {
        text: '多层级地图'
    },
    tooltip: {},
    visualMap: {
        min: 0,
        max: 100,
        left: 'left',
        top: 'bottom',
        text: ['高','低'],
        calculable: true
    },
    series: [
        {
            name: '多层级地图',
            type: 'map',
            mapType: 'china',
            roam: true,
            label: {
                normal: {
                    show: true
                },
                emphasis: {
                    show: true
                }
            },
            data: [
                {name: '北京',value: Math.round(Math.random() * 1000)},
                {name: '上海',value: Math.round(Math.random() * 1000)},
                // ... 其他省份数据
            ]
        }
    ]
};

myChart.setOption(option);

3. 实用案例

案例五:城市地图

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

var option = {
    title: {
        text: '城市地图'
    },
    tooltip: {},
    visualMap: {
        min: 0,
        max: 100,
        left: 'left',
        top: 'bottom',
        text: ['高','低'],
        calculable: true
    },
    series: [
        {
            name: '城市地图',
            type: 'map',
            mapType: 'china',
            roam: true,
            label: {
                normal: {
                    show: true
                },
                emphasis: {
                    show: true
                }
            },
            data: [
                {name: '北京',value: Math.round(Math.random() * 1000)},
                {name: '上海',value: Math.round(Math.random() * 1000)},
                // ... 其他城市数据
            ]
        }
    ]
};

myChart.setOption(option);

案例六:行政区划图

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

var option = {
    title: {
        text: '行政区划图'
    },
    tooltip: {},
    visualMap: {
        min: 0,
        max: 100,
        left: 'left',
        top: 'bottom',
        text: ['高','低'],
        calculable: true
    },
    series: [
        {
            name: '行政区划图',
            type: 'map',
            mapType: 'china',
            roam: true,
            label: {
                normal: {
                    show: true
                },
                emphasis: {
                    show: true
                }
            },
            data: [
                {name: '北京',value: Math.round(Math.random() * 1000)},
                {name: '上海',value: Math.round(Math.random() * 1000)},
                // ... 其他行政区划数据
            ]
        }
    ]
};

myChart.setOption(option);

案例七:迁徙地图

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

var option = {
    title: {
        text: '迁徙地图'
    },
    tooltip: {},
    visualMap: {
        min: 0,
        max: 100,
        left: 'left',
        top: 'bottom',
        text: ['高','低'],
        calculable: true
    },
    series: [
        {
            name: '迁徙地图',
            type: 'map',
            mapType: 'china',
            roam: true,
            label: {
                normal: {
                    show: true
                },
                emphasis: {
                    show: true
                }
            },
            data: [
                {name: '北京',value: Math.round(Math.random() * 1000)},
                {name: '上海',value: Math.round(Math.random() * 1000)},
                // ... 其他迁徙数据
            ]
        }
    ]
};

myChart.setOption(option);

总结

以上是 ECharts 地图图表制作的 30 个实用案例,涵盖了基础地图图表、高级地图图表以及实用案例等方面。通过这些案例,相信你已经对 ECharts 地图图表的制作有了初步的了解。在实际应用中,你可以根据自己的需求,对案例进行修改和扩展,以实现更多功能。希望这些案例能帮助你轻松入门 ECharts 地图图表的制作!