funnel.add()方法简介
add(name, attr, value,
funnel_sort="ascending", funnel_gap=0, **kwargs)
name str 图例名称
attr list 属性名称
value list 属性对应的值
funnel_sort str、func
数据排序,可以取ascending,descending,none
funnel_gap int 数据图形间距。默认为0。
attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"] value = [20, 40, 60, 80, 100, 120] funnel = Funnel("漏斗图示例") funnel.add( "商品", attr, value, is_label_show=True, label_pos="inside", label_text_color="#fff", ) page.add(funnel)
#标签显示在外部 funnel2 = Funnel("漏斗图示例", title_pos='center') funnel2.add( "商品", attr, value, is_label_show=True, label_pos="outside", legend_orient="vertical", legend_pos="left", ) page.add(funnel2)
funnel3 = Funnel("漏斗图示例", title_pos='center') funnel3.add( "商品", attr, value, is_label_show=True, label_pos="inside", legend_orient="vertical", legend_pos="left", funnel_sort="ascending" ) page.add(funnel3)
funnel4 = Funnel("漏斗图示例", title_pos='center') funnel4.add( "商品", attr, value, is_label_show=True, label_pos="inside", legend_orient="vertical", legend_pos="left", funnel_sort="ascending", funnel_gap=5, ) page.add(funnel4)
六、完整代码如下所示,可直接运行
from pyecharts import Page from pyecharts import Funnel page = Page() #Funnel(漏斗图) ''' funnel.add()方法简介 add(name, attr, value, funnel_sort="ascending", funnel_gap=0, **kwargs) name str 图例名称 attr list 属性名称 value list 属性对应的值 funnel_sort str、func 数据排序,可以取ascending,descending,none funnel_gap int 数据图形间距。默认为0。 ''' #标签显示在内部 attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"] value = [20, 40, 60, 80, 100, 120] funnel = Funnel("漏斗图示例") funnel.add( "商品", attr, value, is_label_show=True, label_pos="inside", label_text_color="#fff", ) page.add(funnel) #标签显示在外部 funnel2 = Funnel("漏斗图示例", title_pos='center') funnel2.add( "商品", attr, value, is_label_show=True, label_pos="outside", legend_orient="vertical", legend_pos="left", ) page.add(funnel2) #数据按升序排列 funnel3 = Funnel("漏斗图示例", title_pos='center') funnel3.add( "商品", attr, value, is_label_show=True, label_pos="inside", legend_orient="vertical", legend_pos="left", funnel_sort="ascending" ) page.add(funnel3) #指定图形间隔 funnel4 = Funnel("漏斗图示例", title_pos='center') funnel4.add( "商品", attr, value, is_label_show=True, label_pos="inside", legend_orient="vertical", legend_pos="left", funnel_sort="ascending", funnel_gap=5, ) page.add(funnel4) page.render()