仅供自己学习和参考,欢迎交流
import json
from pyecharts.charts import Line
from pyecharts.options import TitleOpts, LabelOpts, LegendOpts, VisualMapOpts, ToolboxOpts
f_us = open("D:/美国.txt", "r", encoding="UTF-8")
f_in = open("D:/印度.txt", "r", encoding="UTF-8")
f_jp = open("D:/日本.txt", "r", encoding="UTF-8")
us_date = f_us.read()
in_date = f_in.read()
jp_date = f_jp.read()
us_date = us_date.replace("jsonp_1629344292311_69436(", "")
in_date = in_date.replace("jsonp_1629350745930_63180(", "")
jp_date = jp_date.replace("jsonp_1629350871167_29498(", "")
us_date = us_date[:-2]
in_date = in_date[:-2]
jp_date = jp_date[:-2]
us_dict = json.loads(us_date)
in_dict = json.loads(in_date)
jp_dict = json.loads(jp_date)
us_trend_date = us_dict["data"][0]["trend"]
us_x_date = us_trend_date["updateDate"][0:314]
us_y_date = us_trend_date["list"][0]["data"][0:314]
in_trend_date = in_dict["data"][0]["trend"]
in_x_date = in_trend_date["updateDate"][0:314]
in_y_date = in_trend_date["list"][0]["data"][0:314]
jp_trend_date = jp_dict["data"][0]["trend"]
jp_x_date = jp_trend_date["updateDate"][0:314]
jp_y_date = jp_trend_date["list"][0]["data"][0:314]
line = Line()
line.add_xaxis(us_x_date)
line.add_yaxis("美国确诊人数", us_y_date, label_opts=LabelOpts(is_show=False))
line.add_yaxis("印度确诊人数", in_y_date, label_opts=LabelOpts(is_show=False))
line.add_yaxis("日本确诊人数", jp_y_date, label_opts=LabelOpts(is_show=False))
line.set_global_opts(
title_opts=TitleOpts(title="全球疫情折线图", pos_left="center", pos_bottom="1%"),
legend_opts=LegendOpts(is_show=True),
toolbox_opts=ToolboxOpts(is_show=True),
visualmap_opts=VisualMapOpts(is_show=True, min_=1000, max_=20000000, range_text=["High", "Low"])
)
line.render("疫情折线图.html")
f_us.close()
f_in.close()
f_jp.close()