卡片图
利用opts.TitleOpts()来模仿卡片图的样式。
####### 卡片图 ##########
from pyecharts import options as opts
import pyecharts
from pyecharts.charts import *
def big_card(color_bg='orange',color_sub='blue',title1='重要指标',subtitle1='1205',width1='250px',height1='150px',):
c = (
Pie(
init_opts=opts.InitOpts(
width=width1,
height=height1,
bg_color = color_bg,
)
)#不重要
.set_global_opts(
title_opts=opts.TitleOpts(
title=title1,
subtitle=subtitle1,
item_gap = 25,
padding=20,
subtitle_textstyle_opts=opts.TextStyleOpts(color=color_sub,font_weight='bolder',font_size=50,border_width=5,border_radius=2,align='center'),
),
)
)
return c
def page_draggable_layout(request):
page = Page(layout=Page.DraggablePageLayout)
big_card1 = big_card(title1='期间内新人训培训人数',subtitle1='300',color_bg='pink')
big_card1.chart_id = 'A0A'
big_card2 = big_card(title1='期间内通识训培训人数',subtitle1='100',color_bg='orange')
big_card2.chart_id = 'A0B'
big_card3 = big_card(title1='期间内技能认证训鉴定卡数',subtitle1='200',color_bg='green')
big_card3.chart_id = 'A0C'
big_card4 = big_card(title1='技能等级认证训今年通过率',subtitle1='55.04%',color_bg='grey')
big_card4.chart_id = 'A0D'
page.add(
big_card1,
big_card2,
big_card3,
big_card4,
)
page.render(file_address2+ os.sep + "page_draggable_layout.html")
page.save_resize_html(file_address2+ os.sep + "page_draggable_layout.html", cfg_file=file_address2+os.sep+r"chart_config.json", dest=file_address2+"my_new_charts.html")
if __name__ == "__main__":
page_draggable_layout(request)
print('执行完毕')
|