-4

I need a sample code to represent some data in Gantt chart using flask.

1 Answers1

-1

Although your question is too broad and you don't seem to have tried anything I will give you an example. Let's say we have the following code:

from flask import Flask, request, render_template

app = Flask(__name__)
app.config['DEBUG'] = True


def init_gantt():
    import matplotlib.pyplot as plt

    fig, gnt = plt.subplots()
    gnt.set_ylim(0, 50)

    gnt.set_xlim(0, 160)
    gnt.set_xlabel('seconds since start')
    gnt.set_ylabel('Processor')

    gnt.set_yticks([15, 25, 35])
    gnt.set_yticklabels(['1', '2', '3'])

    gnt.grid(True)

    gnt.broken_barh([(40, 50)], (30, 9), facecolors=('tab:orange'))
    gnt.broken_barh([(110, 10), (150, 10)], (10, 9),
                    facecolors='tab:blue')

    gnt.broken_barh([(10, 50), (100, 20), (130, 10)], (20, 9),
                    facecolors=('tab:red'))

    plt.savefig("your_path/gantt1.png")


@app.route('/')
def index():
    return render_template('gantt.html')


if __name__ == "__main__":
    app.run()

The init_gantt function creates our diagram and saves it to a png file locally. Then you only have to show that image in your template:

gantt.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Gantt</title>
</head>
<body>
<img src="your_path/gantt1.png"/>
</body>
</html>
Kostas Charitidis
  • 2,991
  • 1
  • 12
  • 23