1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
| from flask import Flask, render_template from gevent.pywsgi import WSGIServer from pyecharts.charts import Bar, Grid from pyecharts import options as opts
app = Flask(__name__)
@app.route("/") def index(): bar1 = Bar(init_opts=opts.InitOpts(width='150px', height='100px')) bar1.add_xaxis(["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]) bar1.add_yaxis("商家A", [5, 20, 36, 10, 75, 90]) bar1.set_global_opts(title_opts=opts.TitleOpts(title="Bar1-基本示例", subtitle="Bar1副标题", pos_bottom="93%", pos_right="85%"), legend_opts=opts.LegendOpts(pos_bottom="95%", pos_right="70%"))
bar2 = Bar(init_opts=opts.InitOpts(width='150px', height='100px')) bar2.add_xaxis(["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]) bar2.add_yaxis("商家A", [5, 20, 36, 10, 75, 80]) bar2.set_global_opts(title_opts=opts.TitleOpts(title="Bar2-基本示例", subtitle="Bar2副标题", pos_bottom="93%", pos_left="55%"), legend_opts=opts.LegendOpts(pos_bottom="95%", pos_left="70%"))
bar3 = Bar(init_opts=opts.InitOpts(width='150px', height='100px')) bar3.add_xaxis(["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]) bar3.add_yaxis("商家A", [5, 20, 36, 10, 75, 70]) bar3.set_global_opts(title_opts=opts.TitleOpts(title="Bar3-基本示例", subtitle="Bar3副标题", pos_top="52%", pos_right="85%"), legend_opts=opts.LegendOpts(pos_top="54%", pos_right="70%"))
bar4 = Bar(init_opts=opts.InitOpts(width='150px', height='100px')) bar4.add_xaxis(["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]) bar4.add_yaxis("商家A", [5, 20, 36, 10, 75, 60]) bar4.set_global_opts(title_opts=opts.TitleOpts(title="Bar4-基本示例", subtitle="Bar4副标题", pos_top="52%", pos_left="55%"), legend_opts=opts.LegendOpts(pos_top="54%", pos_left="70%"))
grid = Grid(init_opts=opts.InitOpts(width='960px', height='800px')) grid.add(bar1, grid_opts=opts.GridOpts(pos_bottom="60%", pos_right="60%")) grid.add(bar2, grid_opts=opts.GridOpts(pos_bottom="60%", pos_left="60%")) grid.add(bar3, grid_opts=opts.GridOpts(pos_top="60%", pos_right="60%")) grid.add(bar4, grid_opts=opts.GridOpts(pos_top="60%", pos_left="60%"))
chart1 = grid.render_embed()
return render_template('index.html', chart1=chart1)
if __name__ == '__main__': http_server = WSGIServer(('0.0.0.0', 5000), app) http_server.serve_forever()
|