'commit'
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
from fastapi import APIRouter
|
||||
import json
|
||||
from Model.RenkouModel import RenkouModel
|
||||
|
||||
from Model.RuYuanZaiYuanCountModel import RuYuanZaiYuanModel
|
||||
|
||||
# 创建APIRouter实例
|
||||
@@ -11,14 +10,6 @@ router = APIRouter(prefix="/bigscreen", tags=["大屏展示"])
|
||||
async def root():
|
||||
return {"message": "Welcome to YunNan Education World!"}
|
||||
|
||||
@router.get("/population/chart/{year}")
|
||||
async def get_population_chart_config(year: str = "2024"):
|
||||
return RenkouModel.generate_population_chart_config(year)
|
||||
|
||||
@router.get("/population/urbanization")
|
||||
async def get_urbanization_rate_chart_config():
|
||||
return RenkouModel.generate_urbanization_rate_chart_config()
|
||||
|
||||
@router.get("/school/preschool/chart")
|
||||
async def get_preschool_education_chart_config():
|
||||
return RuYuanZaiYuanModel.generate_preschool_education_config()
|
||||
|
Binary file not shown.
@@ -1,129 +0,0 @@
|
||||
import json
|
||||
|
||||
from pyecharts import options as opts
|
||||
from pyecharts.charts import Bar, Line
|
||||
from pyecharts.globals import CurrentConfig
|
||||
|
||||
from Config.Config import ONLINE_HOST
|
||||
CurrentConfig.ONLINE_HOST = ONLINE_HOST
|
||||
|
||||
class RenkouModel:
|
||||
@staticmethod
|
||||
def load_population_data():
|
||||
try:
|
||||
# 获取当前文件所在目录的父目录,然后找到Data文件夹
|
||||
data_path = "./Data/RenKou.json"
|
||||
|
||||
with open(data_path, "r", encoding="utf-8") as f:
|
||||
data = json.load(f)
|
||||
return data
|
||||
except Exception as e:
|
||||
print(f"读取人口数据出错: {e}")
|
||||
return []
|
||||
|
||||
@staticmethod
|
||||
def generate_population_chart_config(year="2024"):
|
||||
# 加载人口数据
|
||||
population_data = RenkouModel.load_population_data()
|
||||
# 筛选出州市级数据
|
||||
cities = [item for item in population_data if len(item["area_code"]) == 9 and item["area_code"].endswith("000") and item["area_code"][4:6] == "00" and item["area_code"][2:8] != "000000"]
|
||||
# 提取城市名称和人口数据
|
||||
city_names = [city["area_name"] for city in cities]
|
||||
total_populations = [city["total_population"].get(year, 0) for city in cities]
|
||||
urban_populations = [city["urban_population"].get(year, 0) for city in cities]
|
||||
rural_populations = [city["rural_population"].get(year, 0) for city in cities]
|
||||
|
||||
# 创建柱状图
|
||||
c = (
|
||||
Bar()
|
||||
.add_xaxis(city_names)
|
||||
.add_yaxis("总人口", total_populations, stack="stack1")
|
||||
.add_yaxis("城镇人口", urban_populations, stack="stack1")
|
||||
.add_yaxis("农村人口", rural_populations, stack="stack1")
|
||||
.set_global_opts(
|
||||
title_opts=opts.TitleOpts(
|
||||
title=f"云南省各州市人口分布图({year}年)",
|
||||
pos_top="1%",
|
||||
pos_left="center"
|
||||
),
|
||||
tooltip_opts=opts.TooltipOpts(
|
||||
trigger="axis",
|
||||
axis_pointer_type="shadow"
|
||||
),
|
||||
legend_opts=opts.LegendOpts(
|
||||
pos_top="8%",
|
||||
pos_right="5%"
|
||||
),
|
||||
datazoom_opts=[opts.DataZoomOpts()],
|
||||
xaxis_opts=opts.AxisOpts(
|
||||
axislabel_opts=opts.LabelOpts(rotate=45)
|
||||
),
|
||||
yaxis_opts=opts.AxisOpts(
|
||||
name="人口数量(万人)",
|
||||
name_location="middle",
|
||||
name_gap=40
|
||||
)
|
||||
)
|
||||
.set_series_opts(
|
||||
label_opts=opts.LabelOpts(is_show=False),
|
||||
markline_opts=opts.MarkLineOpts(
|
||||
data=[opts.MarkLineItem(type_="average", name="平均值")]
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
# 获取图表的选项配置
|
||||
options_str = c.dump_options_with_quotes()
|
||||
return json.loads(options_str)
|
||||
|
||||
@staticmethod
|
||||
def generate_urbanization_rate_chart_config():
|
||||
# 加载人口数据
|
||||
population_data = RenkouModel.load_population_data()
|
||||
|
||||
# 筛选出州市级数据
|
||||
cities = [item for item in population_data if len(item["area_code"]) == 9 and item["area_code"].endswith("000") and item["area_code"][4:6] == "00" and item["area_code"][2:8] != "000000"]
|
||||
|
||||
# 提取城市名称
|
||||
city_names = [city["area_name"] for city in cities]
|
||||
|
||||
# 创建折线图
|
||||
line = (
|
||||
Line()
|
||||
.add_xaxis(city_names)
|
||||
)
|
||||
|
||||
# 添加各年份的城镇化率数据
|
||||
years = ["2020", "2021", "2022", "2023", "2024"]
|
||||
for year in years:
|
||||
urbanization_rates = [city["urbanization_rate"].get(year, 0) for city in cities]
|
||||
line.add_yaxis(f"{year}年", urbanization_rates,
|
||||
markpoint_opts=opts.MarkPointOpts(data=[opts.MarkPointItem(type_="max")]))
|
||||
|
||||
line.set_global_opts(
|
||||
title_opts=opts.TitleOpts(
|
||||
title="云南省各州市城镇化率变化趋势",
|
||||
pos_top="1%",
|
||||
pos_left="center"
|
||||
),
|
||||
tooltip_opts=opts.TooltipOpts(trigger="axis"),
|
||||
legend_opts=opts.LegendOpts(
|
||||
pos_top="8%",
|
||||
pos_right="5%"
|
||||
),
|
||||
datazoom_opts=[opts.DataZoomOpts()],
|
||||
xaxis_opts=opts.AxisOpts(
|
||||
axislabel_opts=opts.LabelOpts(rotate=45)
|
||||
),
|
||||
yaxis_opts=opts.AxisOpts(
|
||||
name="城镇化率(%)",
|
||||
name_location="middle",
|
||||
name_gap=40,
|
||||
min_=0,
|
||||
max_=100
|
||||
)
|
||||
)
|
||||
|
||||
# 获取图表的选项配置
|
||||
options_str = line.dump_options_with_quotes()
|
||||
return json.loads(options_str)
|
Binary file not shown.
BIN
Model/__pycache__/RuYuanZaiYuanCountModel.cpython-310.pyc
Normal file
BIN
Model/__pycache__/RuYuanZaiYuanCountModel.cpython-310.pyc
Normal file
Binary file not shown.
@@ -1,49 +0,0 @@
|
||||
<!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://gcore.jsdelivr.net/npm/echarts@6.0.0/dist/echarts.min.js"></script>
|
||||
<link rel="stylesheet" href="css/style.css">
|
||||
</head>
|
||||
<body>
|
||||
<div class="header">
|
||||
<h1>云南教育决策研究服务系统</h1>
|
||||
<p>数据可视化展示平台</p>
|
||||
</div>
|
||||
|
||||
<div class="chart-container">
|
||||
<div class="tabs">
|
||||
<div class="tab active" data-tab="population">人口数据图表</div>
|
||||
<div class="tab" data-tab="urbanization">城镇化率图表</div>
|
||||
</div>
|
||||
|
||||
<div class="tab-content active" id="population-tab">
|
||||
<h2>云南省各州市人口分布</h2>
|
||||
<div class="controls">
|
||||
<select id="yearSelect">
|
||||
<option value="2020">2020年</option>
|
||||
<option value="2021">2021年</option>
|
||||
<option value="2022">2022年</option>
|
||||
<option value="2023">2023年</option>
|
||||
<option value="2024" selected>2024年</option>
|
||||
</select>
|
||||
</div>
|
||||
<div id="populationChart" class="chart"></div>
|
||||
</div>
|
||||
|
||||
<div class="tab-content" id="urbanization-tab">
|
||||
<h2>云南省各州市城镇化率变化趋势</h2>
|
||||
<div class="controls">
|
||||
</div>
|
||||
<div id="urbanizationChart" class="chart"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 引入外部JS -->
|
||||
<script src="js/jquery-3.7.1.min.js"></script>
|
||||
<script src="js/script.js"></script>
|
||||
</body>
|
||||
</html>
|
Reference in New Issue
Block a user