'commit'
This commit is contained in:
@@ -1 +1,5 @@
|
|||||||
EXCEL_PATH=r'D:\dsWork\YunNanProject\Doc\数据库-2015-2024-v2.xlsx'
|
# 数据库
|
||||||
|
EXCEL_PATH = r'D:\dsWork\YunNanProject\Doc\数据库-2015-2024-v2.xlsx'
|
||||||
|
|
||||||
|
# Echarts的静态资源路径
|
||||||
|
ONLINE_HOST = "https://gcore.jsdelivr.net/npm/echarts@6.0.0/dist/"
|
||||||
|
Binary file not shown.
@@ -1,20 +1,18 @@
|
|||||||
import json
|
import json
|
||||||
import os
|
|
||||||
from pyecharts import options as opts
|
from pyecharts import options as opts
|
||||||
from pyecharts.charts import Bar, Line
|
from pyecharts.charts import Bar, Line
|
||||||
from pyecharts.globals import CurrentConfig
|
from pyecharts.globals import CurrentConfig
|
||||||
|
|
||||||
# 配置使用自定义的ECharts路径
|
from Config.Config import ONLINE_HOST
|
||||||
CurrentConfig.ONLINE_HOST = "https://gcore.jsdelivr.net/npm/echarts@6.0.0/dist/"
|
CurrentConfig.ONLINE_HOST = ONLINE_HOST
|
||||||
|
|
||||||
class RenkouModel:
|
class RenkouModel:
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def load_population_data():
|
def load_population_data():
|
||||||
try:
|
try:
|
||||||
# 获取当前文件所在目录的父目录,然后找到Data文件夹
|
# 获取当前文件所在目录的父目录,然后找到Data文件夹
|
||||||
current_dir = os.path.dirname(os.path.abspath(__file__))
|
data_path = "./Data/RenKou.json"
|
||||||
project_root = os.path.dirname(current_dir) # 修正路径计算,只需要上一级目录
|
|
||||||
data_path = os.path.join(project_root, "Data", "RenKou.json")
|
|
||||||
|
|
||||||
with open(data_path, "r", encoding="utf-8") as f:
|
with open(data_path, "r", encoding="utf-8") as f:
|
||||||
data = json.load(f)
|
data = json.load(f)
|
||||||
@@ -27,10 +25,8 @@ class RenkouModel:
|
|||||||
def generate_population_chart_config(year="2024"):
|
def generate_population_chart_config(year="2024"):
|
||||||
# 加载人口数据
|
# 加载人口数据
|
||||||
population_data = RenkouModel.load_population_data()
|
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"]
|
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]
|
city_names = [city["area_name"] for city in cities]
|
||||||
total_populations = [city["total_population"].get(year, 0) for city in cities]
|
total_populations = [city["total_population"].get(year, 0) for city in cities]
|
||||||
|
Binary file not shown.
Reference in New Issue
Block a user