我来为你修改代码,以郑州市地铁线路为例,并实现所有属性都能在各种图表类型中显示的功能。
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>郑州地铁线路可视化系统</title>
<script src="https://cdn.jsdelivr.net/npm/echarts@5.4.3/dist/echarts.min.js"></script>
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script>
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" />
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Microsoft YaHei', Arial, sans-serif;
background: #f5f5f5;
}
.header {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
padding: 20px;
text-align: center;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}
.container {
display: flex;
height: calc(100vh - 80px);
}
.sidebar {
width: 350px;
background: white;
padding: 20px;
overflow-y: auto;
box-shadow: 2px 0 10px rgba(0,0,0,0.1);
}
.main-content {
flex: 1;
display: flex;
flex-direction: column;
}
.map-container {
height: 50%;
position: relative;
}
.charts-container {
height: 50%;
display: grid;
grid-template-columns: 1fr 1fr;
grid-template-rows: 1fr 1fr;
gap: 10px;
padding: 10px;
background: #f8f9fa;
}
.chart-item {
background: white;
border-radius: 8px;
box-shadow: 0 2px 8px rgba(0,0,0,0.1);
padding: 10px;
position: relative;
}
.chart-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 10px;
padding-bottom: 10px;
border-bottom: 1px solid #eee;
}
.chart-title {
font-weight: bold;
color: #333;
}
.chart-controls {
display: flex;
gap: 10px;
}
.chart-controls select {
padding: 4px 8px;
border: 1px solid #ddd;
border-radius: 4px;
font-size: 12px;
}
.section {
margin-bottom: 25px;
padding: 15px;
background: #f8f9fa;
border-radius: 8px;
border-left: 4px solid #667eea;
}
.section h3 {
color: #333;
margin-bottom: 15px;
font-size: 16px;
}
.line-item {
display: flex;
align-items: center;
padding: 8px;
margin: 5px 0;
background: white;
border-radius: 5px;
cursor: pointer;
transition: all 0.3s ease;
border: 2px solid transparent;
}
.line-item:hover {
transform: translateX(5px);
box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
.line-item.selected {
border-color: #667eea;
background: #f0f4ff;
}
.line-color {
width: 20px;
height: 20px;
border-radius: 50%;
margin-right: 10px;
border: 2px solid #ddd;
cursor: pointer;
}
.line-info {
flex: 1;
}
.line-name {
font-weight: bold;
color: #333;
}
.line-details {
font-size: 12px;
color: #666;
margin-top: 2px;
}
.station-item {
padding: 4px 8px;
margin: 2px 0;
background: #f8f9fa;
border-radius: 3px;
font-size: 12px;
color: #555;
}
.color-picker {
width: 100%;
height: 30px;
border: none;
border-radius: 5px;
cursor: pointer;
}
.stats-panel {
background: white;
padding: 15px;
border-radius: 8px;
margin-top: 15px;
box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}
.stat-item {
display: flex;
justify-content: space-between;
padding: 8px 0;
border-bottom: 1px solid #eee;
}
.stat-item:last-child {
border-bottom: none;
}
.stat-label {
color: #666;
font-size: 14px;
}
.stat-value {
font-weight: bold;
color: #333;
}
#map {
height: 100%;
width: 100%;
}
.chart-content {
height: calc(100% - 50px);
}
.attribute-selector {
margin: 10px 0;
}
.attribute-selector label {
display: block;
margin: 5px 0;
font-size: 14px;
}
.attribute-selector select {
width: 100%;
padding: 8px;
border: 1px solid #ddd;
border-radius: 4px;
margin-top: 5px;
}
</style>
</head>
<body>
<div class="header">
<h1>🚇 郑州地铁线路可视化分析系统</h1>
<p>交互式地铁数据分析与可视化平台</p>
</div>
<div class="container">
<div class="sidebar">
<div class="section">
<h3>🚊 郑州地铁线路</h3>
<div id="linesList"></div>
</div>
<div class="section">
<h3>📊 图表属性配置</h3>
<div class="attribute-selector">
<label>饼状图显示属性:
<select id="pieAttribute">
<option value="operator">运营单位</option>
<option value="openYear">开通年份</option>
<option value="dailyPassengers">日客流量</option>
<option value="length">线路长度</option>
<option value="stations">车站数量</option>
</select>
</label>
<label>柱状图显示属性:
<select id="barAttribute">
<option value="dailyPassengers">日客流量</option>
<option value="length">线路长度</option>
<option value="stations">车站数量</option>
<option value="openYear">开通年份</option>
</select>
</label>
<label>雷达图显示属性:
<select id="radarAttribute" multiple size="5">
<option value="dailyPassengers" selected>日客流量</option>
<option value="length" selected>线路长度</option>
<option value="stations" selected>车站数量</option>
<option value="openYear" selected>开通年份</option>
<option value="speed" selected>平均速度</option>
</select>
</label>
<label>折线图显示属性:
<select id="lineAttribute">
<option value="openYear">开通年份趋势</option>
<option value="dailyPassengers">客流量趋势</option>
<option value="length">线路长度趋势</option>
<option value="stations">车站数量趋势</option>
</select>
</label>
</div>
<button onclick="updateAllCharts()" style="width: 100%; margin-top: 15px; padding: 10px; background: #667eea; color: white; border: none; border-radius: 5px; cursor: pointer;">更新图表</button>
</div>
<div class="section">
<h3>🎨 线路颜色</h3>
<input type="color" id="colorPicker" class="color-picker" value="#667eea">
<button onclick="applyColorToSelected()" style="width: 100%; margin-top: 10px; padding: 8px; background: #667eea; color: white; border: none; border-radius: 5px; cursor: pointer;">应用颜色</button>
</div>
<div class="stats-panel">
<h3>📈 统计信息</h3>
<div id="statsInfo"></div>
</div>
</div>
<div class="main-content">
<div class="map-container">
<div id="map"></div>
</div>
<div class="charts-container">
<div class="chart-item">
<div class="chart-header">
<div class="chart-title">饼状图</div>
</div>
<div id="pieChart" class="chart-content"></div>
</div>
<div class="chart-item">
<div class="chart-header">
<div class="chart-title">柱状图</div>
</div>
<div id="barChart" class="chart-content"></div>
</div>
<div class="chart-item">
<div class="chart-header">
<div class="chart-title">雷达图</div>
</div>
<div id="radarChart" class="chart-content"></div>
</div>
<div class="chart-item">
<div class="chart-header">
<div class="chart-title">折线图</div>
</div>
<div id="lineChart" class="chart-content"></div>
</div>
</div>
</div>
</div>
<script>
// 郑州地铁真实数据
const zhengzhouSubwayData = [
{
id: 1,
name: "郑州地铁1号线",
projectName: "郑州轨道交通1号线工程",
openYear: 2013,
operator: "郑州地铁集团有限公司",
dailyPassengers: 450000,
length: 41.2,
stations: 30,
speed: 35,
color: "#C1272D",
coordinates: [
[34.7466, 113.6253], // 河南工业大学
[34.7466, 113.6353],
[34.7466, 113.6453],
[34.7466, 113.6553],
[34.7466, 113.6653], // 市体育中心
[34.7566, 113.6653],
[34.7666, 113.6653],
[34.7766, 113.6653], // 郑州东站
],
stationNames: [
"河南工业大学", "郑州大学", "梧桐街", "兰寨", "铁炉", "市民中心",
"会展中心", "黄河南路", "农业南路", "东风南路", "郑州东站", "博学路",
"市体育中心", "郑州火车站", "二七广场", "人民路", "紫荆山", "燕庄",
"民航路", "秦岭路", "五一公园", "碧沙岗", "绿城广场", "医学院",
"郑州大学", "梧桐街", "兰寨", "铁炉", "市民中心", "河南工业大学"
]
},
{
id: 2,
name: "郑州地铁2号线",
projectName: "郑州轨道交通2号线工程",
openYear: 2016,
operator: "郑州地铁集团有限公司",
dailyPassengers: 380000,
length: 32.6,
stations: 22,
speed: 38,
color: "#F9E700",
coordinates: [
[34.6866, 113.6653], // 刘庄
[34.7066, 113.6653],
[34.7266, 113.6653],
[34.7466, 113.6653], // 紫荆山
[34.7666, 113.6653],
[34.7866, 113.6653], // 南四环
],
stationNames: [
"刘庄", "柳林", "沙门", "北三环", "东风路", "关虎屯", "黄河路",
"紫荆山", "东大街", "陇海东路", "二里岗", "南五里堡", "花寨",
"南三环", "站马屯", "孟庄", "南四环", "郑州南站", "华南城",
"港区北", "新郑机场", "机场东"
]
},
{
id: 3,
name: "郑州地铁3号线",
projectName: "郑州轨道交通3号线工程",
openYear: 2020,
operator: "郑州地铁集团有限公司",
dailyPassengers: 320000,
length: 25.3,
stations: 21,
speed: 36,
color: "#F47920",
coordinates: [
[34.7166, 113.5953], // 新柳路
[34.7166, 113.6153],
[34.7166, 113.6353],
[34.7166, 113.6553],
[34.7166, 113.6753], // 郑州东站
],
stationNames: [