Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flask_chartjs_manager-0.1.4.tar.gz (74.2 kB view details)

Uploaded Source

Built Distribution

flask_chartjs_manager-0.1.4-py3-none-any.whl (74.3 kB view details)

Uploaded Python 3

File details

Details for the file flask_chartjs_manager-0.1.4.tar.gz.

File metadata

  • Download URL: flask_chartjs_manager-0.1.4.tar.gz
  • Upload date:
  • Size: 74.2 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

Hashes for flask_chartjs_manager-0.1.4.tar.gz
Algorithm Hash digest
SHA256 4fcb28d1f15fb01a7d5f8d8fcf728a05ba68154814c7637cfdf429639040a37d
MD5 f6056966bcb32edfa97c4b3a26d1898d
BLAKE2b-256 c5d6261579668877afd96e852a270210ef4be8d59165e002f7cd92a3577230e0

See more details on using hashes here.

File details

Details for the file flask_chartjs_manager-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: flask_chartjs_manager-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 74.3 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

Hashes for flask_chartjs_manager-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 8d9ac1f6a028770aca633b1ca9a014a1ed13fba38bffbd21011be3598a97e830
MD5 bc9df40e9222c1973db352829df85928
BLAKE2b-256 11e7109e490b793c0decb8d2481d5c13db4b92a5b72b8d7ef36ae1c98e3daa9e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page