No project description provided
Project description
Flask-ChartJS
Flask-ChartJS provides a simple interface to use ChartJS javascript library with Flask.
Installation
Install the extension with pip:
pip install flask-chartjs-manager
Usage
Once installed the Flask-ChartJS-Manager is easy to use.Let's walk through setting up a basic application. Also please note that this is a very basic guide: we will be taking shortcuts here that you should never take in a real application.
To begin we'll set up a Flask app:
import flask
app = flask.Flask(__name__)
Flask-ChartJS works via a ChartJS object. To kick things off, we'll set up the chartjs manager by instantiating it and telling it about our Flask app:
from flask_chartjs import ChartJSManager
chartjs_manager = ChartJSManager()
chartjs_manager.init_app(app)
This will make available the load_chartjs
function into the templates context so you could load the javascript package easily, like this.
<head>
{{ load_chartjs() }}
</head>
Now we will construct a basic chart.
from flask_chartjs import Chart, DataSet
from flask import render_template
@app.get('/chart-example')
def chart_example():
chart = Chart('income-outcome', 'bar') # Requires at least an ID and a chart type.
dataset_income = DataSet('Income', [100,200,300])
dataset_outcome = DataSet('OutCome', [50,100,150])
chart.data.add_labels('jan', 'feb', 'mar')
chart.data.add_dataset(dataset_income)
chart.data.add_dataset(dataset_outcome)
return render_template('path/to/template.html', my_chart=chart)
Once created you can pass it to a render_template and use it likewise.
<!-- load_chartjs() must be called before this line -->
<div class="my-classes">{{ render_chart(my_chart) }}</div>
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for flask_chartjs_manager-0.1.7.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | b7bfdd12582fa77d365c2c442218d822abab96ef6d443d4804ee2b5ff1521d97 |
|
MD5 | 6686ad78cc9f9ff24e0efb5a25edaae0 |
|
BLAKE2b-256 | a1164f56164037a8df9ad0616be2e1119d80eac12eac1a77367a12ccee22ee83 |
Hashes for flask_chartjs_manager-0.1.7-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a00f18dfb3b4b102ad18f08bc0e6593c96df19305a10bb9f8db03eae4ce6165c |
|
MD5 | 618777fa691c1d575bd3094a6a47b2e8 |
|
BLAKE2b-256 | e24f8e3555f119e4653cbc2a5a58bf92089765e293ffbf8b5c1db40fcd4c1edf |