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
Usage
Once installed the Flask-ChartJS 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 login manager by instantiating it and telling it about our Flask app:
from flask_chartjs import ChartJS
chartjs = ChartJS()
chartjs.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">{{ 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.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | d5ed1a02caffc526771a991734115f6f5186d1097a598451ba13db9cb6de0c93 |
|
MD5 | af04870bfb3b58847600dc5d88fc5658 |
|
BLAKE2b-256 | 169b713d45e195bb9e1688e035b024c5f2f2c806429790c87947e3c3ffe0f137 |
Hashes for flask_chartjs_manager-0.1.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3d79d91d20a44c8472ebb284ecbd86c2d463a438a272d3468b9d6138ba16da41 |
|
MD5 | 12599dc79f29a50ea6215094e764e747 |
|
BLAKE2b-256 | 816ee9cd74604c82deef34c9975854e102ee27e8165c80a9a812682e1493217f |