Flask+Pyecharts+大数据集群(Linux):数据可视化大屏的实现
from flask import Flask, render_template
from pyecharts.charts import Bar, Line
from pyecharts import options as opts
app = Flask(__name__, static_folder="templates")
def bar_base() -> Bar:
c = (
Bar()
.add_xaxis(["A", "B", "C", "D", "E", "F"])
.add_yaxis("Series 1", [10, 20, 30, 40, 50, 60])
.set_global_opts(title_opts=opts.TitleOpts(title="Bar-基本示例"))
)
return c
def line_base() -> Line:
c = (
Line()
.add_xaxis(["A", "B", "C", "D", "E", "F"])
.add_yaxis("Series 1", [10, 20, 30, 40, 50, 60])
.set_global_opts(title_opts=opts.TitleOpts(title="Line-基本示例"))
)
return c
@app.route("/")
def index():
bar_chart = bar_base().render("bar_chart.html")
line_chart = line_base().render("line_chart.html")
return render_template("index.html", bar_chart=bar_chart, line_chart=line_chart)
if __name__ == "__main__":
app.run(debug=True)
这段代码创建了一个简单的Flask应用,其中包含了使用Pyecharts生成的基本条形图和折线图。在路由/
下,使用Pyecharts生成图表,并通过Flask渲染到模板中。最后,在Linux环境下运行Flask应用。这个例子展示了如何将数据可视化集成到Web应用中,便于数据的展示和分析。
评论已关闭