Skip to main content

Easily embed Chart.js charts in Flask apps via jinja from the backend

Project description

FlaskGraph

FlaskGraph makes it dead simple to drop Chart.js charts into your Flask app without touching JavaScript. You just write Python, pass it to your template, and you're done.


🔧 Installation

pip install flaskgraph

⚡ Quickstart

1. Import & Use in Flask

from flaskgraph import graph

@app.route("/")
def dashboard():
    chart = graph.bar(
        ['Jan', 'Feb', 'Mar'],
        [27, 35, 12],
        legend=False,
        label_color='standard',
        grid=False,
        colortheme='sky'
    )
    return render_template("dashboard.html", chart=chart)

2. In Your Template

Include Chart.js in your HTML <head>:

<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>

Render the chart inside a container with a set width (the canvas is included automatically):

<div style="width: 100%; max-width: 600px;">
  {{ chart|safe }}
</div>

📊 Supported Chart Types

graph.bar(labels, data, ...)
graph.line(labels, data, ...)
graph.donut(labels, data, ...)
graph.scatter(labels, data, ...)

Each method returns a fully ready-to-render HTML <canvas> with a Chart.js config script.


🎨 Parameters

Parameter Type Description
labels list X-axis labels
data list Y-axis values
label_color str Label color: "standard", "dark", or "light"
legend bool Show/hide the legend
grid bool Show/hide background grid lines
colortheme str One of the predefined themes below

🌈 Available Color Themes

blue, green, red, yellow, orange,
purple, pink, teal, sky, lime,
slate, gray, zinc,
neon-green, neon-pink, neon-blue

✅ Example

revenue = graph.line(
    ['Q1', 'Q2', 'Q3', 'Q4'],
    [5000, 7000, 4000, 6500],
    label_color='dark',
    legend=True,
    grid=True,
    colortheme='lime'
)
<div style="max-width: 700px;">
  {{ revenue|safe }}
</div>

That's it. No JavaScript. No extra config.

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

flaskgraph-0.1.0.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

flaskgraph-0.1.0-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

Details for the file flaskgraph-0.1.0.tar.gz.

File metadata

  • Download URL: flaskgraph-0.1.0.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for flaskgraph-0.1.0.tar.gz
Algorithm Hash digest
SHA256 1eb2856d66cb2c3c8e905c6deed7198946c61834429c23a574477888b0175b3e
MD5 20132a63e66f2c274300b42420ee2636
BLAKE2b-256 00e0395034b19158ea00956fe04517744602d98a977c0d35918d17b9641aba36

See more details on using hashes here.

File details

Details for the file flaskgraph-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: flaskgraph-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for flaskgraph-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 dc72e9dbb3301ea2d7cf8b52b76205aa87ba2a09deb70c85e7e8b6e7ce5146f8
MD5 b4a2dce81187fdbfbfedf51671d5ea68
BLAKE2b-256 2982cfc95cfbbac123f5343b993153ccd13b5f798fc1aff00b33255f4c5357e8

See more details on using hashes here.

Supported by

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