This commit is contained in:
2025-09-10 20:32:37 +08:00
parent 83edb02cac
commit 5e8b66dc14
2 changed files with 70 additions and 15 deletions

View File

@@ -52,13 +52,23 @@ class RuYuanZaiYuanModel:
calculated_total = enroll_data.get("urban", 0) + enroll_data.get("town", 0) + enroll_data.get("rural", 0) calculated_total = enroll_data.get("urban", 0) + enroll_data.get("town", 0) + enroll_data.get("rural", 0)
total_enroll.append(calculated_total / 10000) # 转换为万人 total_enroll.append(calculated_total / 10000) # 转换为万人
# 添加2022年基数的粉色折线
base_year = "2022"
# 找到2022年在years中的索引位置
base_index = years.index(base_year) if base_year in years else 0
# 获取2022年的总入园数作为基数
base_value = total_enroll[base_index] if base_index < len(total_enroll) else 0
# 创建2022年基数折线数据2022-2024年
base_2022_line = []
for i, year in enumerate(years):
# 只在2022年及之后显示基数线
if i >= base_index:
base_2022_line.append(base_value)
else:
base_2022_line.append(None) # 2022年之前不显示
# 构建ECharts配置 # 构建ECharts配置
option = { option = {
# "title": {
# "text": "云南省学前教育人数统计",
# "left": "center",
# "textStyle": {"color": "#333"}
# },
"tooltip": { "tooltip": {
"trigger": "axis", "trigger": "axis",
"axisPointer": { "axisPointer": {
@@ -71,7 +81,7 @@ class RuYuanZaiYuanModel:
"borderWidth": 1 "borderWidth": 1
}, },
"legend": { "legend": {
"data": ["城区", "镇区", "乡村", "总入园数"], "data": ["城区", "镇区", "乡村", "总入园数", "2022年基数(万人)"],
"top": 30, "top": 30,
"textStyle": {"color": "#333"}, "textStyle": {"color": "#333"},
"icon": "roundRect", "icon": "roundRect",
@@ -112,9 +122,9 @@ class RuYuanZaiYuanModel:
"nameGap": 30, # 增加名称与轴的间距 "nameGap": 30, # 增加名称与轴的间距
"axisLabel": { "axisLabel": {
"formatter": "{value} 万人", "formatter": "{value} 万人",
"color": "#ee6666" "color": "#00a859"
}, },
"axisLine": {"show": True, "lineStyle": {"color": "#ee6666"}}, "axisLine": {"show": True, "lineStyle": {"color": "#00a859"}}, # 改为绿色
"axisTick": {"show": True}, "axisTick": {"show": True},
"splitLine": {"show": False} "splitLine": {"show": False}
} }
@@ -158,10 +168,25 @@ class RuYuanZaiYuanModel:
"type": "line", "type": "line",
"yAxisIndex": 1, "yAxisIndex": 1,
"data": total_enroll, "data": total_enroll,
"lineStyle": {"color": "#ee6666", "width": 3}, "lineStyle": {"color": "#00a859", "width": 3}, # 改为绿色
"symbol": "circle", "symbol": "circle",
"symbolSize": 8, "symbolSize": 8,
"itemStyle": {"color": "#ee6666"} "itemStyle": {"color": "#00a859"} # 改为绿色
},
# 添加2022年基数的粉色折线
{
"name": "2022年基数(万人)",
"type": "line",
"yAxisIndex": 1,
"data": base_2022_line,
"lineStyle": {"color": "#ff9e9e", "width": 2, "type": "solid"},
"symbol": "circle",
"symbolSize": 6,
"itemStyle": {"color": "#ff9e9e"},
"emphasis": {
"focus": "series"
},
"z": 5 # 确保折线图显示在柱状图之上,但在总入园数折线之下
} }
], ],
"grid": { "grid": {
@@ -211,6 +236,21 @@ class RuYuanZaiYuanModel:
calculated_total = (urban_val + town_val + rural_val) / 10000 # 先计算总和再转换为万人 calculated_total = (urban_val + town_val + rural_val) / 10000 # 先计算总和再转换为万人
total_in_school.append(calculated_total) total_in_school.append(calculated_total)
# 添加2022年基数的粉色折线
base_year = "2022"
# 找到2022年在years中的索引位置
base_index = years.index(base_year) if base_year in years else 0
# 获取2022年的总在园数作为基数
base_value = total_in_school[base_index] if base_index < len(total_in_school) else 0
# 创建2022年基数折线数据2022-2024年
base_2022_line = []
for i, year in enumerate(years):
# 只在2022年及之后显示基数线
if i >= base_index:
base_2022_line.append(base_value)
else:
base_2022_line.append(None) # 2022年之前不显示
# 构建ECharts配置 # 构建ECharts配置
option = { option = {
"tooltip": { "tooltip": {
@@ -225,7 +265,7 @@ class RuYuanZaiYuanModel:
"borderWidth": 1 "borderWidth": 1
}, },
"legend": { "legend": {
"data": ["城区", "镇区", "乡村", "总在园数"], "data": ["城区", "镇区", "乡村", "总在园数", "2022年基数(万人)"],
"top": 30, "top": 30,
"textStyle": {"color": "#333"}, "textStyle": {"color": "#333"},
"icon": "roundRect", "icon": "roundRect",
@@ -266,9 +306,9 @@ class RuYuanZaiYuanModel:
"nameGap": 30, "nameGap": 30,
"axisLabel": { "axisLabel": {
"formatter": "{value} 万人", "formatter": "{value} 万人",
"color": "#ee6666" "color": "#00a859" # 改为绿色
}, },
"axisLine": {"show": True, "lineStyle": {"color": "#ee6666"}}, "axisLine": {"show": True, "lineStyle": {"color": "#00a859"}}, # 改为绿色
"axisTick": {"show": True}, "axisTick": {"show": True},
"splitLine": {"show": False} "splitLine": {"show": False}
} }
@@ -312,14 +352,29 @@ class RuYuanZaiYuanModel:
"type": "line", "type": "line",
"yAxisIndex": 1, "yAxisIndex": 1,
"data": total_in_school, "data": total_in_school,
"lineStyle": {"color": "#ee6666", "width": 3}, "lineStyle": {"color": "#00a859", "width": 3}, # 改为绿色
"symbol": "circle", "symbol": "circle",
"symbolSize": 8, "symbolSize": 8,
"itemStyle": {"color": "#ee6666"}, "itemStyle": {"color": "#00a859"}, # 改为绿色
"emphasis": { "emphasis": {
"focus": "series" "focus": "series"
}, },
"z": 10 # 确保折线图显示在最上层 "z": 10 # 确保折线图显示在最上层
},
# 添加2022年基数的粉色折线
{
"name": "2022年基数(万人)",
"type": "line",
"yAxisIndex": 1,
"data": base_2022_line,
"lineStyle": {"color": "#ff9e9e", "width": 2, "type": "solid"},
"symbol": "circle",
"symbolSize": 6,
"itemStyle": {"color": "#ff9e9e"},
"emphasis": {
"focus": "series"
},
"z": 5 # 确保折线图显示在柱状图之上,但在总在园数折线之下
} }
], ],
"grid": { "grid": {