Skip to content

Instantly share code, notes, and snippets.

@moqada
Created December 19, 2014 05:50
Show Gist options
  • Save moqada/b7387465690217e216f7 to your computer and use it in GitHub Desktop.
Save moqada/b7387465690217e216f7 to your computer and use it in GitHub Desktop.
pygal sample on flask
# -*- coding: utf-8 -*-
import pygal
from flask import Flask, Response
app = Flask(__name__)
@app.route('/')
def index():
""" render svg on html """
return """
<html>
<body>
<h1>hello pygal</h1>
<figure>
<embed type="image/svg+xml" src="/graph/" />
</figure>
</body>
</html>'
"""
@app.route('/graph/')
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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment