'commit'
This commit is contained in:
@@ -3,26 +3,73 @@
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>学前教育数据测试</title>
|
||||
<title>云南省学前教育数据</title>
|
||||
<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>
|
||||
<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>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<h1>学前教育招生人数统计</h1>
|
||||
<div id="preschoolChart" style="width: 100%; height: 600px;"></div>
|
||||
<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>
|
||||
<div id="message" class="message"></div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// 初始化图表
|
||||
var preschoolChart = echarts.init(document.getElementById('preschoolChart'));
|
||||
var chartData = null;
|
||||
var currentType = 'both';
|
||||
|
||||
// 显示加载状态
|
||||
function showLoading() {
|
||||
preschoolChart.showLoading();
|
||||
$('#message').text('数据加载中...');
|
||||
}
|
||||
|
||||
// 隐藏加载状态
|
||||
@@ -36,13 +83,29 @@
|
||||
console.error(message);
|
||||
}
|
||||
|
||||
// 渲染图表
|
||||
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);
|
||||
}
|
||||
|
||||
// 加载学前教育数据
|
||||
function loadPreschoolData() {
|
||||
showLoading();
|
||||
$.getJSON('/bigscreen/school/preschool/chart')
|
||||
.done(function(data) {
|
||||
preschoolChart.setOption(data);
|
||||
$('#message').text('数据加载成功');
|
||||
chartData = data;
|
||||
renderChart();
|
||||
})
|
||||
.fail(function(jqXHR, textStatus, errorThrown) {
|
||||
showError(errorThrown || '获取数据失败,请检查接口是否正常');
|
||||
@@ -52,14 +115,21 @@
|
||||
});
|
||||
}
|
||||
|
||||
// 页面加载时加载数据
|
||||
// 按钮点击事件
|
||||
$(document).ready(function() {
|
||||
loadPreschoolData();
|
||||
});
|
||||
|
||||
// 窗口大小变化时调整图表
|
||||
$(window).resize(function() {
|
||||
preschoolChart.resize();
|
||||
$('.btn').click(function() {
|
||||
$('.btn').removeClass('active');
|
||||
$(this).addClass('active');
|
||||
currentType = $(this).data('type');
|
||||
renderChart();
|
||||
});
|
||||
|
||||
// 窗口大小变化时调整图表
|
||||
$(window).resize(function() {
|
||||
preschoolChart.resize();
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
|
Reference in New Issue
Block a user