Files
YunNanProject/static/preschool_education.html

136 lines
4.2 KiB
HTML
Raw Normal View History

2025-09-10 16:14:35 +08:00
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
2025-09-10 16:27:38 +08:00
<title>云南省学前教育数据</title>
2025-09-10 16:14:35 +08:00
<link rel="stylesheet" href="css/style.css">
<script src="https://cdn.jsdelivr.net/npm/echarts@5.4.3/dist/echarts.min.js"></script>
<script src="js/jquery-3.7.1.min.js"></script>
2025-09-10 16:27:38 +08:00
<style>
.chart-controls {
margin: 20px 0;
text-align: center;
}
.btn-group {
display: inline-flex;
border-radius: 4px;
overflow: hidden;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.btn {
padding: 10px 20px;
border: none;
background: #f0f0f0;
cursor: pointer;
font-size: 14px;
transition: all 0.3s;
}
.btn.active {
background: #409eff;
color: white;
}
.btn:hover:not(.active) {
background: #e0e0e0;
}
.container {
max-width: 1200px;
margin: 0 auto;
padding: 20px;
}
h1 {
text-align: center;
color: #333;
margin-bottom: 30px;
}
</style>
2025-09-10 16:14:35 +08:00
</head>
<body>
<div class="container">
2025-09-10 16:27:38 +08:00
<h1>云南省学前教育人数统计</h1>
<div class="chart-controls">
<div class="btn-group">
<button class="btn active" data-type="both">全部显示</button>
<button class="btn" data-type="enroll">入园数总量</button>
<button class="btn" data-type="inschool">在园数总量</button>
</div>
</div>
<div id="preschoolChart" style="width: 100%; height: 500px;"></div>
2025-09-10 16:14:35 +08:00
<div id="message" class="message"></div>
</div>
<script>
// 初始化图表
var preschoolChart = echarts.init(document.getElementById('preschoolChart'));
2025-09-10 16:27:38 +08:00
var chartData = null;
var currentType = 'both';
2025-09-10 16:14:35 +08:00
// 显示加载状态
function showLoading() {
preschoolChart.showLoading();
}
// 隐藏加载状态
function hideLoading() {
preschoolChart.hideLoading();
}
// 显示错误信息
function showError(message) {
$('#message').text('错误: ' + message);
console.error(message);
}
2025-09-10 16:27:38 +08:00
// 渲染图表
function renderChart() {
if (!chartData) return;
var option = JSON.parse(JSON.stringify(chartData));
// 根据当前选择的类型过滤数据
if (currentType === 'enroll') {
option.series = [option.series[0]]; // 只显示入园总数
} else if (currentType === 'inschool') {
option.series = [option.series[1]]; // 只显示在园总数
}
preschoolChart.setOption(option);
}
2025-09-10 16:14:35 +08:00
// 加载学前教育数据
function loadPreschoolData() {
showLoading();
$.getJSON('/bigscreen/school/preschool/chart')
.done(function(data) {
2025-09-10 16:27:38 +08:00
chartData = data;
renderChart();
2025-09-10 16:14:35 +08:00
})
.fail(function(jqXHR, textStatus, errorThrown) {
showError(errorThrown || '获取数据失败,请检查接口是否正常');
})
.always(function() {
hideLoading();
});
}
2025-09-10 16:27:38 +08:00
// 按钮点击事件
2025-09-10 16:14:35 +08:00
$(document).ready(function() {
loadPreschoolData();
2025-09-10 16:27:38 +08:00
$('.btn').click(function() {
$('.btn').removeClass('active');
$(this).addClass('active');
currentType = $(this).data('type');
renderChart();
});
// 窗口大小变化时调整图表
$(window).resize(function() {
preschoolChart.resize();
});
2025-09-10 16:14:35 +08:00
});
</script>
</body>
</html>