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.1.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.1-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: flaskgraph-0.1.1.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.1.tar.gz
Algorithm Hash digest
SHA256 c6712ee4b49fb6adfd4e59ebd7d920a8db55dab45c168a41fc571e612478050e
MD5 ec675d32d473252eac2488c0cdfa980c
BLAKE2b-256 319aacd92c1c4a019cbae991d9361375561be1661658f5c7827b039106c30cf8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: flaskgraph-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 4.0 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 60cd0a28f91b22d0a42a5c05da8b14810e82641cf14676cfc365af25b5309a45
MD5 b9f79265211def3fdbe0bb342abc33c8
BLAKE2b-256 f86b24713c261ae93a2a3af16d7a71ebb72171b7c9abbadebb8970c39617dc0d

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