pygal 能画 svg 图表, 从 pypi.python.org 下载 pygal-2.4.0.tar.gz , 其中源代码是学习 lxml 的范例.
flask_bar1.py
import pygal
from flask import Flask, Response
app = Flask(__name__)
@app.route('/')
def index():
return app.send_static_file('index.html')
@app.route('/bar1svg/')
def graph():
""" render svg graph """
bar_chart = pygal.Bar()
bar_chart.add('Fibonacci', [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55])
return Response(response=bar_chart.render(), content_type='image/svg+xml')
if __name__ == '__main__':
app.run(debug=True, port=80)
#app.run(host='0.0.0.0', port=80)
static/index.html
<!DOCTYPE html>
<html>
<body>
<h3>flask and pygal bar </h3>
<figure>
<embed type="image/svg+xml" src="/bar1svg/" height="400" width="600" />
</figure>
</body>
</html>
运行 python flask_bar1.py