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 login manager. 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
File details
Details for the file flask_chartjs_manager-0.1.0.tar.gz
.
File metadata
- Download URL: flask_chartjs_manager-0.1.0.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.2.2 CPython/3.8.10 Linux/5.10.16.3-microsoft-standard-WSL2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3dab0693ea6df727a275494725fc646203be250f84b28fb6f15cb672c53a88c9 |
|
MD5 | 253c97719757778fd0abc67ebf743c44 |
|
BLAKE2b-256 | 11ca669e2c4099b5a167c4b37b0d79439c01faa391d2079dd3fb7fe8cb1713e1 |
File details
Details for the file flask_chartjs_manager-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: flask_chartjs_manager-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.2.2 CPython/3.8.10 Linux/5.10.16.3-microsoft-standard-WSL2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4007928191cc2299a510480ef44e198da056ec44fa630209a1fc242730dab657 |
|
MD5 | 7b28f8eda473ddb6993038b22a97b428 |
|
BLAKE2b-256 | 1ef4016eb73078131a1afec1ab08d0b9b386732970f065618bf799ace8f09311 |