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.5.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | b7f9700f46ee6f65c63e1a28b94772051bc401b9d9bf03b5801b66fa2208b57c |
|
MD5 | ba0c2bfe70bab6be54dcef0f9ce76b31 |
|
BLAKE2b-256 | c0333ee482ab7175b04c8eb414f187372576ce77801b72ffef32d261da8d4c14 |
Hashes for flask_chartjs_manager-0.1.5-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 08da178bd712bcae8d39bb57eae673309a62b331725102705ca29933d95df306 |
|
MD5 | 2515fc9bde50fc3c162deb4f336ab2cb |
|
BLAKE2b-256 | 9267cf343331a60b1f4c67edc98e33ac1c10c716a187e6aa4d54e0c72fd6c756 |