案例一:中国省市区级地图展示
ECharts 提供了丰富的地图类型,包括中国省市区级地图。以下是一个简单的案例,展示如何使用 ECharts 展示中国省市区级地图。
// 引入 ECharts 主模块
var echarts = require('echarts/lib/echarts');
// 引入中国地图数据
require('echarts/map/js/china');
// 基于准备好的dom,初始化echarts实例
var myChart = echarts.init(document.getElementById('main'));
// 指定图表的配置项和数据
var option = {
title: {
text: '中国省市区级地图展示'
},
tooltip: {
trigger: 'item'
},
series: [{
name: '中国',
type: 'map',
mapType: 'china',
label: {
show: true
},
data: [{
name: '北京',
value: Math.round(Math.random() * 1000)
}, {
name: '上海',
value: Math.round(Math.random() * 1000)
}, {
name: '广东',
value: Math.round(Math.random() * 1000)
}]
}]
};
// 使用刚指定的配置项和数据显示图表。
myChart.setOption(option);
案例二:世界地图展示
除了中国地图,ECharts 还支持世界地图。以下是一个简单的世界地图展示案例。
// 引入 ECharts 主模块
var echarts = require('echarts/lib/echarts');
// 引入世界地图数据
require('echarts/map/js/world');
// 基于准备好的dom,初始化echarts实例
var myChart = echarts.init(document.getElementById('main'));
// 指定图表的配置项和数据
var option = {
title: {
text: '世界地图展示'
},
tooltip: {
trigger: 'item'
},
series: [{
name: '世界',
type: 'map',
mapType: 'world',
label: {
show: true
},
data: [{
name: '美国',
value: Math.round(Math.random() * 1000)
}, {
name: '加拿大',
value: Math.round(Math.random() * 1000)
}, {
name: '英国',
value: Math.round(Math.random() * 1000)
}]
}]
};
// 使用刚指定的配置项和数据显示图表。
myChart.setOption(option);
案例三:自定义地图
ECharts 支持自定义地图,你可以使用 GeoJSON 格式的地图数据来创建自定义地图。以下是一个使用自定义地图的案例。
// 引入 ECharts 主模块
var echarts = require('echarts/lib/echarts');
// 引入自定义地图数据
require('echarts/map/js/custom');
// 基于准备好的dom,初始化echarts实例
var myChart = echarts.init(document.getElementById('main'));
// 指定图表的配置项和数据
var option = {
title: {
text: '自定义地图展示'
},
tooltip: {
trigger: 'item'
},
series: [{
name: '自定义地图',
type: 'map',
mapType: 'custom',
label: {
show: true
},
data: [{
name: '区域1',
value: Math.round(Math.random() * 1000)
}, {
name: '区域2',
value: Math.round(Math.random() * 1000)
}]
}]
};
// 使用刚指定的配置项和数据显示图表。
myChart.setOption(option);
案例四:地图上的热力图
在地图上添加热力图可以更直观地展示数据的分布情况。以下是一个在地图上添加热力图的案例。
// 引入 ECharts 主模块
var echarts = require('echarts/lib/echarts');
// 引入中国地图数据
require('echarts/map/js/china');
// 基于准备好的dom,初始化echarts实例
var myChart = echarts.init(document.getElementById('main'));
// 指定图表的配置项和数据
var option = {
title: {
text: '地图上的热力图'
},
tooltip: {
trigger: 'item'
},
series: [{
name: '中国',
type: 'map',
mapType: 'china',
label: {
show: true
},
data: [{
name: '北京',
value: Math.round(Math.random() * 1000)
}, {
name: '上海',
value: Math.round(Math.random() * 1000)
}, {
name: '广东',
value: Math.round(Math.random() * 1000)
}],
itemStyle: {
normal: {
areaColor: '#323c48',
borderColor: '#111'
},
emphasis: {
areaColor: '#2a333d'
}
},
markPoint: {
symbol: 'pin',
symbolSize: 50,
data: [{
name: '北京',
value: Math.round(Math.random() * 1000)
}, {
name: '上海',
value: Math.round(Math.random() * 1000)
}, {
name: '广东',
value: Math.round(Math.random() * 1000)
}]
}
}]
};
// 使用刚指定的配置项和数据显示图表。
myChart.setOption(option);
案例五:地图上的折线图
在地图上添加折线图可以展示数据的变化趋势。以下是一个在地图上添加折线图的案例。
// 引入 ECharts 主模块
var echarts = require('echarts/lib/echarts');
// 引入中国地图数据
require('echarts/map/js/china');
// 基于准备好的dom,初始化echarts实例
var myChart = echarts.init(document.getElementById('main'));
// 指定图表的配置项和数据
var option = {
title: {
text: '地图上的折线图'
},
tooltip: {
trigger: 'item'
},
series: [{
name: '中国',
type: 'map',
mapType: 'china',
label: {
show: true
},
data: [{
name: '北京',
value: Math.round(Math.random() * 1000)
}, {
name: '上海',
value: Math.round(Math.random() * 1000)
}, {
name: '广东',
value: Math.round(Math.random() * 1000)
}],
markLine: {
silent: false,
symbol: ['none', 'circle'],
symbolSize: 8,
data: [{
name: '北京',
xAxis: 116.407526,
yAxis: 39.90403,
value: Math.round(Math.random() * 1000)
}, {
name: '上海',
xAxis: 121.473701,
yAxis: 31.230416,
value: Math.round(Math.random() * 1000)
}, {
name: '广东',
xAxis: 113.280637,
yAxis: 23.125178,
value: Math.round(Math.random() * 1000)
}]
}
}]
};
// 使用刚指定的配置项和数据显示图表。
myChart.setOption(option);
案例六:地图上的散点图
在地图上添加散点图可以展示数据的分布情况。以下是一个在地图上添加散点图的案例。
// 引入 ECharts 主模块
var echarts = require('echarts/lib/echarts');
// 引入中国地图数据
require('echarts/map/js/china');
// 基于准备好的dom,初始化echarts实例
var myChart = echarts.init(document.getElementById('main'));
// 指定图表的配置项和数据
var option = {
title: {
text: '地图上的散点图'
},
tooltip: {
trigger: 'item'
},
series: [{
name: '中国',
type: 'map',
mapType: 'china',
label: {
show: true
},
data: [{
name: '北京',
value: Math.round(Math.random() * 1000)
}, {
name: '上海',
value: Math.round(Math.random() * 1000)
}, {
name: '广东',
value: Math.round(Math.random() * 1000)
}],
markPoint: {
symbol: 'pin',
symbolSize: 50,
data: [{
name: '北京',
value: Math.round(Math.random() * 1000)
}, {
name: '上海',
value: Math.round(Math.random() * 1000)
}, {
name: '广东',
value: Math.round(Math.random() * 1000)
}]
}
}]
};
// 使用刚指定的配置项和数据显示图表。
myChart.setOption(option);
案例七:地图上的柱状图
在地图上添加柱状图可以展示数据的分布情况。以下是一个在地图上添加柱状图的案例。
// 引入 ECharts 主模块
var echarts = require('echarts/lib/echarts');
// 引入中国地图数据
require('echarts/map/js/china');
// 基于准备好的dom,初始化echarts实例
var myChart = echarts.init(document.getElementById('main'));
// 指定图表的配置项和数据
var option = {
title: {
text: '地图上的柱状图'
},
tooltip: {
trigger: 'item'
},
series: [{
name: '中国',
type: 'map',
mapType: 'china',
label: {
show: true
},
data: [{
name: '北京',
value: Math.round(Math.random() * 1000)
}, {
name: '上海',
value: Math.round(Math.random() * 1000)
}, {
name: '广东',
value: Math.round(Math.random() * 1000)
}],
markPoint: {
symbol: 'pin',
symbolSize: 50,
data: [{
name: '北京',
value: Math.round(Math.random() * 1000)
}, {
name: '上海',
value: Math.round(Math.random() * 1000)
}, {
name: '广东',
value: Math.round(Math.random() * 1000)
}]
}
}]
};
// 使用刚指定的配置项和数据显示图表。
myChart.setOption(option);
案例八:地图上的饼图
在地图上添加饼图可以展示数据的占比情况。以下是一个在地图上添加饼图的案例。
// 引入 ECharts 主模块
var echarts = require('echarts/lib/echarts');
// 引入中国地图数据
require('echarts/map/js/china');
// 基于准备好的dom,初始化echarts实例
var myChart = echarts.init(document.getElementById('main'));
// 指定图表的配置项和数据
var option = {
title: {
text: '地图上的饼图'
},
tooltip: {
trigger: 'item'
},
series: [{
name: '中国',
type: 'map',
mapType: 'china',
label: {
show: true
},
data: [{
name: '北京',
value: Math.round(Math.random() * 1000)
}, {
name: '上海',
value: Math.round(Math.random() * 1000)
}, {
name: '广东',
value: Math.round(Math.random() * 1000)
}],
markPoint: {
symbol: 'pin',
symbolSize: 50,
data: [{
name: '北京',
value: Math.round(Math.random() * 1000)
}, {
name: '上海',
value: Math.round(Math.random() * 1000)
}, {
name: '广东',
value: Math.round(Math.random() * 1000)
}]
}
}]
};
// 使用刚指定的配置项和数据显示图表。
myChart.setOption(option);
案例九:地图上的环形图
在地图上添加环形图可以展示数据的占比情况。以下是一个在地图上添加环形图的案例。
// 引入 ECharts 主模块
var echarts = require('echarts/lib/echarts');
// 引入中国地图数据
require('echarts/map/js/china');
// 基于准备好的dom,初始化echarts实例
var myChart = echarts.init(document.getElementById('main'));
// 指定图表的配置项和数据
var option = {
title: {
text: '地图上的环形图'
},
tooltip: {
trigger: 'item'
},
series: [{
name: '中国',
type: 'map',
mapType: 'china',
label: {
show: true
},
data: [{
name: '北京',
value: Math.round(Math.random() * 1000)
}, {
name: '上海',
value: Math.round(Math.random() * 1000)
}, {
name: '广东',
value: Math.round(Math.random() * 1000)
}],
markPoint: {
symbol: 'pin',
symbolSize: 50,
data: [{
name: '北京',
value: Math.round(Math.random() * 1000)
}, {
name: '上海',
value: Math.round(Math.random() * 1000)
}, {
name: '广东',
value: Math.round(Math.random() * 1000)
}]
}
}]
};
// 使用刚指定的配置项和数据显示图表。
myChart.setOption(option);
案例十:地图上的雷达图
在地图上添加雷达图可以展示数据的综合情况。以下是一个在地图上添加雷达图的案例。
// 引入 ECharts 主模块
var echarts = require('echarts/lib/echarts');
// 引入中国地图数据
require('echarts/map/js/china');
// 基于准备好的dom,初始化echarts实例
var myChart = echarts.init(document.getElementById('main'));
// 指定图表的配置项和数据
var option = {
title: {
text: '地图上的雷达图'
},
tooltip: {
trigger: 'item'
},
series: [{
name: '中国',
type: 'map',
mapType: 'china',
label: {
show: true
},
data: [{
name: '北京',
value: Math.round(Math.random() * 1000)
}, {
name: '上海',
value: Math.round(Math.random() * 1000)
}, {
name: '广东',
value: Math.round(Math.random() * 1000)
}],
markPoint: {
symbol: 'pin',
symbolSize: 50,
data: [{
name: '北京',
value: Math.round(Math.random() * 1000)
}, {
name: '上海',
value: Math.round(Math.random() * 1000)
}, {
name: '广东',
value: Math.round(Math.random() * 1000)
}]
}
}]
};
// 使用刚指定的配置项和数据显示图表。
myChart.setOption(option);
案例十一:地图上的漏斗图
在地图上添加漏斗图可以展示数据的分布情况。以下是一个在地图上添加漏斗图的案例。
// 引入 ECharts 主模块
var echarts = require('echarts/lib/echarts');
// 引入中国地图数据
require('echarts/map/js/china');
// 基于准备好的dom,初始化echarts实例
var myChart = echarts.init(document.getElementById('main'));
// 指定图表的配置项和数据
var option = {
title: {
text: '地图上的漏斗图'
},
tooltip: {
trigger: 'item'
},
series: [{
name: '中国',
type: 'map',
mapType: 'china',
label: {
show: true
},
data: [{
name: '北京',
value: Math.round(Math.random() * 1000)
}, {
name: '上海',
value: Math.round(Math.random() * 1000)
}, {
name: '广东',
value: Math.round(Math.random() * 1000)
}],
markPoint: {
symbol: 'pin',
symbolSize: 50,
data: [{
name: '北京',
value: Math.round(Math.random() * 1000)
}, {
name: '上海',
value: Math.round(Math.random() * 1000)
}, {
name: '广东',
value: Math.round(Math.random() * 1000)
}]
}
}]
};
// 使用刚指定的配置项和数据显示图表。
myChart.setOption(option);
案例十二:地图上的气泡图
在地图上添加气泡图可以展示数据的分布情况。以下是一个在地图上添加气泡图的案例。
”`javascript // 引入 ECharts 主模块 var echarts = require(‘echarts/lib/echarts’); // 引入中国地图数据 require(‘echarts/map/js/china’);
// 基于准备好的dom,初始化echarts实例 var myChart = echarts.init(document.getElementById(‘main’));
// 指定图表的配置项和数据 var option = {
title: {
text: '地图上的气泡图'
},
tooltip: {
trigger: 'item'
},
series: [{
name: '中国',
type: 'map',
mapType: 'china',
label: {
show: true
},
data: [{
name: '北京',
value: Math.round(Math.random() * 1000)
}, {
name: '上海',
value: Math.round(Math.random() * 1000)
}, {
name: '广东',
value: Math.round(Math.random() * 1000)
}],
markPoint: {
symbol: 'pin',
symbolSize: 50,
data: [{
name: '北京',
value: Math.round(Math.random() * 1000)