Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

296
Vistas
I use Python Flask and javascript to build a line chart, but it is not working although I can see the values are present in chrome inspect elements

I am trying to build a line chart by using python Flask and HTML. Here is my HTML scripts

<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="https://cdn.jsdelivr.net/npm/chart.js@2.9.4/dist/Chart.min.js"></script>
</head>

<body>

    
    <canvas id="lineChart" width="900" height="400"></canvas>
    <script>
        var ctx = document.getElementById("lineChart").getContext("2d");
        var lineChart = new Chart (ctx, {
            type: "line",
            data: {
                labels: {{ labels | safe }}
                datasets: [
                    {
                        label: "Room 1 Temperature",
                        data: {{ values | safe }},
                        fill: false,
                        borderColor: "rgb(75, 192, 192)",
                        lineTension: 0.1
                    }
                ]
            },
            options: {
                responsive: false
            }
        });
    </script>
    
</body>

</html>

And here is the python scripts:

from flask import Flask, render_template
app = Flask(__name__)

@app.route('/test')
def test():
  data = [
    ("a", 70),
    ("b", 50),
    ("c", 10),
    ("d", 60),
    ("e", 50),
    ("a", 90),
  ]

labels = [row[0] for row in data]
values = [row[1] for row in data]

return render_template('test.html', labels=labels, values=values)

the problem is it displays nothing when I run it, but this use case is working fine.

What makes me even more confuse is, I can see the labels and values variables are already present in html when I troubleshoot in chrome.

Can anyone tell me what I did it wrongly? Thank you in advance

enter image description here

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You just forgot to add comma after labels.

enter image description here

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda