Merge branch 'main' of http://10.10.14.176:3000/huanghai/YunNanProject
This commit is contained in:
@@ -4,8 +4,10 @@ from pyecharts.charts import Bar, Line
|
|||||||
from pyecharts.globals import CurrentConfig
|
from pyecharts.globals import CurrentConfig
|
||||||
|
|
||||||
from Config.Config import ONLINE_HOST
|
from Config.Config import ONLINE_HOST
|
||||||
|
|
||||||
CurrentConfig.ONLINE_HOST = ONLINE_HOST
|
CurrentConfig.ONLINE_HOST = ONLINE_HOST
|
||||||
|
|
||||||
|
|
||||||
class RuYuanZaiYuanModel:
|
class RuYuanZaiYuanModel:
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def load_student_data():
|
def load_student_data():
|
||||||
@@ -38,15 +40,15 @@ class RuYuanZaiYuanModel:
|
|||||||
years = [str(year) for year in range(2015, 2025)]
|
years = [str(year) for year in range(2015, 2025)]
|
||||||
|
|
||||||
# 构建学前教育数据
|
# 构建学前教育数据
|
||||||
urban_data = [] # 城区数据
|
urban_data = [] # 城区数据
|
||||||
town_data = [] # 镇区数据
|
town_data = [] # 镇区数据
|
||||||
rural_data = [] # 乡村数据
|
rural_data = [] # 乡村数据
|
||||||
total_enroll = [] # 总入园数
|
total_enroll = [] # 总入园数
|
||||||
|
|
||||||
for year in years:
|
for year in years:
|
||||||
enroll_data = yunnan_enroll["education_data"]["preschool"].get(year, {})
|
enroll_data = yunnan_enroll["education_data"]["preschool"].get(year, {})
|
||||||
urban_data.append(enroll_data.get("urban", 0) / 10000) # 转换为万人
|
urban_data.append(enroll_data.get("urban", 0) / 10000) # 转换为万人
|
||||||
town_data.append(enroll_data.get("town", 0) / 10000) # 转换为万人
|
town_data.append(enroll_data.get("town", 0) / 10000) # 转换为万人
|
||||||
rural_data.append(enroll_data.get("rural", 0) / 10000) # 转换为万人
|
rural_data.append(enroll_data.get("rural", 0) / 10000) # 转换为万人
|
||||||
# 计算总和作为总入园数,而非使用文件中的total字段
|
# 计算总和作为总入园数,而非使用文件中的total字段
|
||||||
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)
|
||||||
@@ -69,21 +71,31 @@ class RuYuanZaiYuanModel:
|
|||||||
|
|
||||||
# 构建ECharts配置
|
# 构建ECharts配置
|
||||||
option = {
|
option = {
|
||||||
|
"grid": {
|
||||||
|
"left": 0,
|
||||||
|
"right": 0,
|
||||||
|
"top": 40,
|
||||||
|
"bottom": 10,
|
||||||
|
"containLabel": True,
|
||||||
|
},
|
||||||
|
"textStyle": {
|
||||||
|
"color": "#fff",
|
||||||
|
},
|
||||||
"tooltip": {
|
"tooltip": {
|
||||||
"trigger": "axis",
|
"trigger": "axis",
|
||||||
"axisPointer": {
|
"axisPointer": {
|
||||||
"type": "cross",
|
"type": "cross",
|
||||||
"crossStyle": {"color": "#999"}
|
"crossStyle": {"color": "#999"}
|
||||||
},
|
},
|
||||||
"textStyle": {"color": "#333"},
|
"textStyle": {"color": "#fff"},
|
||||||
"backgroundColor": "rgba(255, 255, 255, 0.8)",
|
"backgroundColor": "rgba(96,98,102,0.8)",
|
||||||
"borderColor": "rgba(0, 0, 0, 0.2)",
|
"borderColor": "rgba(255,255,255,0.3)",
|
||||||
"borderWidth": 1
|
"borderWidth": 1
|
||||||
},
|
},
|
||||||
"legend": {
|
"legend": {
|
||||||
"data": ["城区", "镇区", "乡村", "总入园数", "2022年基数(万人)"],
|
"data": ["城区", "镇区", "乡村", "总入园数", "2022年基数(万人)"],
|
||||||
"top": 30,
|
"top": 0,
|
||||||
"textStyle": {"color": "#333"},
|
"textStyle": {"color": "#fff"},
|
||||||
"icon": "roundRect",
|
"icon": "roundRect",
|
||||||
"itemWidth": 12,
|
"itemWidth": 12,
|
||||||
"itemHeight": 12
|
"itemHeight": 12
|
||||||
@@ -92,86 +104,66 @@ class RuYuanZaiYuanModel:
|
|||||||
{
|
{
|
||||||
"type": "category",
|
"type": "category",
|
||||||
"data": years,
|
"data": years,
|
||||||
"axisPointer": {"type": "shadow"},
|
"axisPointer": {type: "shadow"},
|
||||||
"axisLabel": {"color": "#333"},
|
"axisLine": {"lineStyle": {"color": "#fff"}},
|
||||||
"axisLine": {"lineStyle": {"color": "#333"}}
|
"axisLabel": {"color": "#fff"},
|
||||||
|
"nameTextStyle": {"color": "#fff"}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"yAxis": [
|
"yAxis": [
|
||||||
{
|
{
|
||||||
"type": "value",
|
"type": "value",
|
||||||
"name": "人数",
|
|
||||||
"min": 0,
|
"min": 0,
|
||||||
"max": 100,
|
"max": 25,
|
||||||
"interval": 20,
|
"interval": 5,
|
||||||
"axisLabel": {
|
"axisLabel": {
|
||||||
"formatter": "{value} 万人",
|
"formatter": "{value}"
|
||||||
"color": "#333"
|
, "color": "#fff"
|
||||||
},
|
}
|
||||||
"axisLine": {"lineStyle": {"color": "#333"}},
|
|
||||||
"splitLine": {"lineStyle": {"color": "rgba(0,0,0,0.1)"}}
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "value",
|
"type": "value",
|
||||||
"name": "总入园数",
|
|
||||||
"min": 0,
|
"min": 0,
|
||||||
"max": 140,
|
"max": 25,
|
||||||
"interval": 20,
|
"interval": 5,
|
||||||
"position": "right",
|
"axisLabel": {"formatter": "{value}", "color": "#fff"},
|
||||||
"nameLocation": "end", # 将名称放在轴末端
|
},
|
||||||
"nameGap": 30, # 增加名称与轴的间距
|
|
||||||
"axisLabel": {
|
|
||||||
"formatter": "{value} 万人",
|
|
||||||
"color": "#00a859"
|
|
||||||
},
|
|
||||||
"axisLine": {"show": True, "lineStyle": {"color": "#00a859"}}, # 改为绿色
|
|
||||||
"axisTick": {"show": True},
|
|
||||||
"splitLine": {"show": False}
|
|
||||||
}
|
|
||||||
],
|
],
|
||||||
"series": [
|
"series": [
|
||||||
{
|
{
|
||||||
"name": "城区",
|
"name": "城区",
|
||||||
"type": "bar",
|
"type": "bar",
|
||||||
|
"tooltip": "{valueFormatter: (v) = > v 万人}",
|
||||||
"data": urban_data,
|
"data": urban_data,
|
||||||
"itemStyle": {
|
"itemStyle": {
|
||||||
"color": "#5470c6",
|
"borderRadius": [6, 6, 0, 0],
|
||||||
"borderRadius": [6, 6, 0, 0]
|
}
|
||||||
},
|
|
||||||
"barWidth": "25%", # 增加柱子宽度
|
|
||||||
"barGap": "-10%" # 设置负数让柱子重叠以减少空隙
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "镇区",
|
"name": "镇区",
|
||||||
"type": "bar",
|
"type": "bar",
|
||||||
"data": town_data,
|
"data": town_data,
|
||||||
|
"tooltip": "{valueFormatter: (v) = > v 万人}",
|
||||||
"itemStyle": {
|
"itemStyle": {
|
||||||
"color": "#91cc75",
|
"borderRadius": [6, 6, 0, 0],
|
||||||
"borderRadius": [6, 6, 0, 0]
|
|
||||||
},
|
},
|
||||||
"barWidth": "25%", # 增加柱子宽度
|
|
||||||
"barGap": "-10%" # 设置负数让柱子重叠以减少空隙
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "乡村",
|
"name": "乡村",
|
||||||
"type": "bar",
|
"type": "bar",
|
||||||
"data": rural_data,
|
"data": rural_data,
|
||||||
|
"tooltip": "{valueFormatter: (v) = > v 万人}",
|
||||||
"itemStyle": {
|
"itemStyle": {
|
||||||
"color": "#fac858",
|
|
||||||
"borderRadius": [6, 6, 0, 0]
|
"borderRadius": [6, 6, 0, 0]
|
||||||
},
|
},
|
||||||
"barWidth": "25%", # 增加柱子宽度
|
|
||||||
"barGap": "-10%" # 设置负数让柱子重叠以减少空隙
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "总入园数",
|
"name": "总入园数",
|
||||||
"type": "line",
|
"type": "line",
|
||||||
"yAxisIndex": 1,
|
"yAxisIndex": 1,
|
||||||
"data": total_enroll,
|
"data": total_enroll,
|
||||||
"lineStyle": {"color": "#00a859", "width": 3}, # 改为绿色
|
"tooltip": "{valueFormatter: (v) = > v 万人}",
|
||||||
"symbol": "circle",
|
|
||||||
"symbolSize": 8,
|
|
||||||
"itemStyle": {"color": "#00a859"} # 改为绿色
|
|
||||||
},
|
},
|
||||||
# 添加2022年基数的粉色折线
|
# 添加2022年基数的粉色折线
|
||||||
{
|
{
|
||||||
@@ -180,21 +172,9 @@ class RuYuanZaiYuanModel:
|
|||||||
"yAxisIndex": 1,
|
"yAxisIndex": 1,
|
||||||
"data": base_2022_line,
|
"data": base_2022_line,
|
||||||
"lineStyle": {"color": "#ff9e9e", "width": 2, "type": "solid"},
|
"lineStyle": {"color": "#ff9e9e", "width": 2, "type": "solid"},
|
||||||
"symbol": "circle",
|
"tooltip": "{valueFormatter: (v) = > v 万人}",
|
||||||
"symbolSize": 6,
|
|
||||||
"itemStyle": {"color": "#ff9e9e"},
|
|
||||||
"emphasis": {
|
|
||||||
"focus": "series"
|
|
||||||
},
|
|
||||||
"z": 5 # 确保折线图显示在柱状图之上,但在总入园数折线之下
|
|
||||||
}
|
}
|
||||||
],
|
]
|
||||||
"grid": {
|
|
||||||
"left": "3%",
|
|
||||||
"right": "8%", # 增加右侧边距
|
|
||||||
"bottom": "3%",
|
|
||||||
"containLabel": True
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return option
|
return option
|
||||||
|
|
||||||
@@ -213,9 +193,9 @@ class RuYuanZaiYuanModel:
|
|||||||
years = [str(year) for year in range(2015, 2025)]
|
years = [str(year) for year in range(2015, 2025)]
|
||||||
|
|
||||||
# 构建学前教育数据
|
# 构建学前教育数据
|
||||||
urban_data = [] # 城区数据
|
urban_data = [] # 城区数据
|
||||||
town_data = [] # 镇区数据
|
town_data = [] # 镇区数据
|
||||||
rural_data = [] # 乡村数据
|
rural_data = [] # 乡村数据
|
||||||
total_in_school = [] # 总在园数
|
total_in_school = [] # 总在园数
|
||||||
|
|
||||||
for year in years:
|
for year in years:
|
||||||
@@ -229,7 +209,7 @@ class RuYuanZaiYuanModel:
|
|||||||
|
|
||||||
# 转换为万人并添加到各自列表
|
# 转换为万人并添加到各自列表
|
||||||
urban_data.append(urban_val / 10000) # 转换为万人
|
urban_data.append(urban_val / 10000) # 转换为万人
|
||||||
town_data.append(town_val / 10000) # 转换为万人
|
town_data.append(town_val / 10000) # 转换为万人
|
||||||
rural_data.append(rural_val / 10000) # 转换为万人
|
rural_data.append(rural_val / 10000) # 转换为万人
|
||||||
|
|
||||||
# 计算总和并转换为万人
|
# 计算总和并转换为万人
|
||||||
|
Reference in New Issue
Block a user