def order_chart(): # 今日各状态订单总金额 pie2 = Pie() pie2.add("", list(order_status_total.items())) pie2.set_global_opts(title_opts=opts.TitleOpts(title="今日各状态订单总金额")) pie2.set_series_opts(label_opts=opts.LabelOpts(formatter="{b}: {c}")) return pie2.dump_options_with_quotes()
def foregin_city_all(): path = readPath + '/各国各地区疫情信息' path2 = savaPath + '/各国疫情严重程度排名前十地区信息' dwf.createFile(path2) Filelist = [] # 将当前文件夹内的所有表名存放此列表 for home, dirs, files in os.walk(path): for filename in files: Filelist.append(filename) # 判断数据是否存在 def checknan(name): if np.any(pd.isnull(name)) == True: name.fillna(value="0", inplace=True) # 随机颜色生成用于制作南丁格尔玫瑰图 def randomcolor(kind): colors = [] for i in range(kind): colArr = ['1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'] color = "" for i in range(6): color += colArr[random.randint(0, 14)] colors.append("#" + color) return colors for i in Filelist: page1 = Page() data = pd.read_excel(readPath + '/各国各地区疫情信息/%s' % (i), index=False) data_sort = data.sort_values(axis=0, ascending=False, by=['confirm']) data_message = data_sort.head(10) # 提取疫情严重程度排名前十地区的信息 n = i[:-5] # 只提取国家名,不要后缀(.xlsx) checknan(data_message['confirm']) checknan(data_message['heal']) checknan(data_message['dead']) y1_confirm = data_message['confirm'] y1_confirm = list(y1_confirm) y1_confirm = [int(i) for i in y1_confirm] y2_dead = data_message['dead'] y2_dead = list(y2_dead) y2_dead = [int(i) for i in y2_dead] y3_heal = data_message['heal'] y3_heal = list(y3_heal) y3_heal = [int(i) for i in y3_heal] name_list = [] for j in data_message['name']: name_list.append(j) x = name_list color_series = randomcolor(len(x)) # Bars = ( # Bar(init_opts=opts.InitOpts(width='1080px',height='700px')) # .add_xaxis(xaxis_data=x) # .add_yaxis(series_name='确诊人数', yaxis_data=y1_confirm) # ) #####画南丁格尔玫瑰图########## # 画出确诊人数的图 fig = Pie(init_opts=opts.InitOpts(width='500px', height='700px')) fig.add("", [list(z) for z in zip(x, y1_confirm)], radius=['30%', '135%'], center=['50%', '65%'], rosetype='area') fig.set_global_opts(title_opts=opts.TitleOpts(title=n + '疫情严重程度排名前十地区的确诊人数'), legend_opts=opts.LegendOpts(is_show=False)) fig.set_series_opts(label_opts=opts.LabelOpts(is_show=True, position='inside', font_size=12, formatter='{b}:{c}例', font_style='italic', font_weight='bold', font_family='Microsoft YaHei')) # b:province;c:num fig.set_colors(color_series) # 画出死亡人数的图 fig1 = Pie(init_opts=opts.InitOpts(width='500px', height='700px')) fig1.add("", [list(z) for z in zip(x, y2_dead)], radius=['30%', '135%'], center=['50%', '65%'], rosetype='area') fig1.set_global_opts(title_opts=opts.TitleOpts(title=n + '疫情严重程度排名前十地区的死亡人数'), legend_opts=opts.LegendOpts(is_show=False)) fig1.set_series_opts(label_opts=opts.LabelOpts(is_show=True, position='inside', font_size=12, formatter='{b}:{c}例', font_style='italic', font_weight='bold', font_family='Microsoft YaHei')) # b:province;c:num # 画出治愈人数的图 fig2 = Pie(init_opts=opts.InitOpts(width='500px', height='700px')) fig2.add("", [list(z) for z in zip(x, y3_heal)], radius=['30%', '135%'], center=['50%', '65%'], rosetype='area') fig2.set_global_opts(title_opts=opts.TitleOpts(title=n + '疫情严重程度排名前十地区的治愈人数'), legend_opts=opts.LegendOpts(is_show=False)) fig2.set_series_opts(label_opts=opts.LabelOpts(is_show=True, position='inside', font_size=12, formatter='{b}:{c}例', font_style='italic', font_weight='bold', font_family='Microsoft YaHei')) # b:province;c:num page1.add(fig) # 将图像加入同一页 page1.add(fig1) # 将图像加入同一页 page1.add(fig2) # 将图像加入同一页 page1.render(savaPath + '/各国疫情严重程度排名前十地区信息/%s.html' % (n), index=False) if flag: dwf.write_to_file(savaPath + '/各国疫情严重程度排名前十地区信息/(确诊)%s.txt' % (n),str(fig.dump_options_with_quotes())) dwf.write_to_file(savaPath + '/各国疫情严重程度排名前十地区信息/(死亡)%s.txt' % (n),str(fig1.dump_options_with_quotes())) dwf.write_to_file(savaPath + '/各国疫情严重程度排名前十地区信息/(治愈)%s.txt' % (n),str(fig2.dump_options_with_quotes()))