def treeChart(df):
    tree = Tree()
    tree.add('',  df, 
        orient="TB",
        label_opts=opts.LabelOpts(
            position="top",
            horizontal_align="right",
            vertical_align="middle",
            rotate=-90,
        ),
    )
    tree.set_global_opts(title_opts=opts.TitleOpts(title="Tree"))
    return tree
Exemplo n.º 2
0
def generate_chart_html(table, title, click_link):
    chart = Tree(init_opts=opts.InitOpts(
        theme='white', width='1024px', height='1000px', chart_id='cb_tree'))
    chart.add_js_funcs(
        """
        chart_cb_tree.on('click', function(x){
            if(x.data['is_child'] == undefined) {return true;}
            if ($('#cb_detail_list').length==0){
                $(document.body).append('<div id=\\'cb_detail_list\\'></div>')
            }
            $.get('""" + click_link +
        """?key=' + encodeURIComponent(x['data']['name']), function(result){
                $('#cb_detail_list').html(result)
                $('body,html').animate({scrollTop: $('#cb_detail_list').offset().top}, 500);
            })
        })
    """)

    data = get_data(table)
    chart.add(
        series_name='',
        data=data,
        initial_tree_depth=1,
        label_opts=opts.LabelOpts(is_show=False),
    )
    chart.set_global_opts(title_opts=opts.TitleOpts(
        title="=========" + title + "=========",
        subtitle_textstyle_opts=opts.TextStyleOpts(font_weight='bold',
                                                   font_size='15px'),
        pos_left='center',
        pos_top='-1px',
    ),
                          tooltip_opts=opts.TooltipOpts(is_show=False))
    chart.set_series_opts(label_opts=opts.LabelOpts(formatter=JsCode(
        """function (x){return x.data['name'] + '(均值:' + x.data['value'] + ', ' + x.data['count'] + x.data['suffix'] + ')';}"""
    )))
    return chart.render_embed('template.html', env)
Exemplo n.º 3
0
    d2["children"] = l
    d2["name"] = name
    data2.append(d2)

#  最外层树
dic2 = {}
dic2["children"] = data2
dic2["name"] = "关键词"
data.append(dic2)
print(data)

# 需要调整画布大小
tree = Tree(init_opts=opts.InitOpts(width='2000px', height='15000px'))
# 两个树分支的距离增大
tree.add("", data, collapse_interval=100)
tree.set_global_opts(title_opts=opts.TitleOpts(title="LDA主题模型"))
tree.render(u'./tree.html')

# 用如下程序也行
# C = Collector()
#
#
# @C.funcs
# def tree_base() -> Tree:
#
#     c = (
#         Tree()
#         .add("", data, collapse_interval=100)
#         # ._set_collapse_interval(10)
#         .set_global_opts(title_opts=opts.TitleOpts(title="LDA主题模型"))
#     )