def drawBar(title, data, series_name, x_label, y_label, savedir='results'): checkDir(savedir) chart = Bar(title) chart.set_options(labels=list(data.keys()), x_label=x_label, y_label=y_label) chart.add_series(series_name, list(data.values())) chart.render(os.path.join(savedir, title + '.html'))
def bar_base(): chart = Bar("Bar-基本示例", width="100%") chart.set_options(labels=["可乐", "雪碧", "橙汁", "绿茶", "奶茶", "百威", "青岛"], x_label="I'm xlabel", y_label="I'm ylabel") chart.add_series("series-A", [127, 33, 110, 29, 146, 121, 36]) return put_html(chart.render_notebook())
def gen_bar_base() -> Bar: c = Bar("Bar") c.set_options(labels=["A", "B"], x_label="I'm xlabel", y_label="I'm ylabel") c.add_series("series-A", ["1", "2"]) return c
def create_chart_extension_dict(extension_dict): extension_dict = dict( sorted(extension_dict.items(), key=lambda item: item[1])) labels = list(extension_dict.keys()) values = list(extension_dict.values()) chart = Bar("The chart for the number of file extensions") chart.set_options(labels=labels, x_label="Extensions", y_label="Number of extensions", colors=['#E09DE1' for _ in range(len(labels))]) chart.add_series("The number of extensions", values) return chart
def create_chart_file_size_dict(file_size_dict): file_size_dict = dict( sorted(file_size_dict.items(), key=lambda item: item[1])) labels = list(file_size_dict.keys()) values = list(file_size_dict.values()) chart = Bar( "The chart for the distribution of file sizes of each extension") chart.set_options(labels=labels, x_label="Extensions", y_label="Sum of file sizes", colors=['#1EAFAE' for _ in range(len(labels))]) chart.add_series("The Sum of sizes", values) return chart
def create_chart(labels: list, values: list): chart = Bar("Food comparison") chart.set_options(labels=labels, x_label="Food", y_label="Delicious level") chart.add_series("Delicious level", values) return chart
def bar_base() -> Bar: chart = Bar("Bar-基本示例") chart.set_options(labels=Faker.choose(), x_label="I'm xlabel", y_label="I'm ylabel") chart.add_series("series-A", Faker.values()) return chart
def bar_tickcount_colors(): chart = Bar("Bar-调整颜色") chart.set_options(labels=Faker.choose(), y_tick_count=10, colors=Faker.colors) chart.add_series("series-A", Faker.values()) return chart
def pyecharts(): from pyecharts.charts import Bar from pyecharts.faker import Faker from pyecharts import options as opts from pyecharts.charts import Polar from pyecharts.charts import HeatMap from pyecharts.charts import Tree r1 = ['草莓', '芒果', '葡萄', '雪梨', '西瓜', '柠檬', '车厘子'] r2 = [127, 33, 110, 29, 146, 121, 36] r3 = [25, 87, 114, 131, 130, 94, 146] c1 = (Bar({ "width": "100%" }).add_xaxis(r1).add_yaxis("商家A", r2).add_yaxis("商家B", r3).set_global_opts( title_opts=opts.TitleOpts(title="Bar-基本示例", subtitle="我是副标题"))) c2 = (Polar({ "width": "100%" }).add_schema( radiusaxis_opts=opts.RadiusAxisOpts(data=Faker.week, type_="category"), angleaxis_opts=opts.AngleAxisOpts(is_clockwise=True, max_=10), ).add("A", [1, 2, 3, 4, 3, 5, 1], type_="bar").set_global_opts( title_opts=opts.TitleOpts(title="Polar-RadiusAxis")).set_series_opts( label_opts=opts.LabelOpts(is_show=True))) data = [{ "children": [ { "name": "B" }, { "children": [{ "children": [{ "name": "I" }], "name": "E" }, { "name": "F" }], "name": "C", }, { "children": [ { "children": [{ "name": "J" }, { "name": "K" }], "name": "G" }, { "name": "H" }, ], "name": "D", }, ], "name": "A", }] c3 = (Tree({ "width": "100%" }).add("", data).set_global_opts(title_opts=opts.TitleOpts(title="Tree-基本示例"))) value = [[i, j, int(i * j * 3.14 * 314 % 50)] for i in range(24) for j in range(7)] c4 = (HeatMap({ "width": "100%" }).add_xaxis(Faker.clock).add_yaxis( "series0", Faker.week, value, label_opts=opts.LabelOpts(is_show=True, position="inside"), ).set_global_opts( title_opts=opts.TitleOpts(title="HeatMap-Label 显示"), visualmap_opts=opts.VisualMapOpts(), )) put_grid([[put_html(c1.render_notebook()), put_html(c2.render_notebook())], [put_html(c3.render_notebook()), put_html(c4.render_notebook())]], cell_width='1fr', cell_height='1fr')