如果要把 pyecharts 里的饼图嵌入其他页面,有的时候需要调整饼图的位置。
不调整可能会显示成这样:
调整后的效果是这样:
关键代码在于:
center=["40%", "60%"]
def pie_base_proc(p_dict, p_list) -> Pie:
c = (
Pie(init_opts=opts.InitOpts(width=p_dict['width'],height=p_dict['height']))
.add("", p_list,center=["40%", "60%"])
.set_global_opts(title_opts=opts.TitleOpts(title=p_dict['title']),
legend_opts=opts.LegendOpts(orient=p_dict['orient'], pos_left=p_dict['pos_left'], pos_top=p_dict['pos_top']))
.set_series_opts(label_opts=opts.LabelOpts(formatter="{b}", position='inside'))
)
return c
def lx_data_Pie(m_dict):
p_dict = {'title':m_dict['title'], 'width':'300px', 'height': '300px'}
# horizontal vertical
p_dict['orient'] ="horizontal"
p_dict['pos_left'] = "0%"
p_dict['pos_top'] = "5%"
m_data = m_dict['m_data']
p_list = [list(z) for z in zip(m_data[0], m_data[1])]
return pie_base_proc(p_dict,p_list)