Created
November 20, 2020 22:43
-
-
Save nick3499/f64237cb54000c097317b55481226cfe to your computer and use it in GitHub Desktop.
Pygal Bar Chart: Python, Flask, pygal, HTML, Jinja2, decorator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>Bar Chart: Fibonacci</title> | |
</head> | |
<body> | |
<!-- bar chart --> | |
<div><embed src={{ chart|safe }} /></div> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/python | |
'''Renders bar graph to web page based on Fibonacci sequence.''' | |
from flask import Flask | |
from flask import render_template | |
import pygal | |
APP = Flask(__name__) # Flask instance | |
@APP.route('/') | |
def render_bar_chart(): | |
'''Renders bar graph to web page based on Fibonacci sequence.''' | |
bar_chart = pygal.Bar(height=300) # instance of Bar class | |
bar_chart.title = 'Fibonacci sequence' # title of bar chart | |
bar_chart.add('Fibonacci', [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55]) # add fibo data to chart | |
chart = bar_chart.render_data_uri() # render bar chart | |
return render_template('index.htm', chart=chart) # render Jinja2 template | |
if __name__ == '__main__': | |
APP.run(host='localhost', port=3000) # if standalone |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Original repo: https://github.com/nick3499/pygal_bar_chart
#Python #Flask #Pygal #ChartingLibrary #Chart