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

515
Vistas
How to add data to Chart.js on ejs using for loop?

I have two datasets coming from Express called cDate, cPrice and they have data.length elements. I want to draw these datas on a chart.I tried many things but the graphic is not updating. My final sample code is here, many thanks !

 <% for(i=0; i<data.length; i++){  %>
    <script>
      var ctx = document.querySelector("#myChart");
      var myChart = new Chart(ctx, {
        type: 'line',
        data: {
          labels: ['<%= cDate[i] %>'],
          datasets: [
            {
              data: ['<%= cPrice[i] %>'],
              label: ['<%= name[0] %>'], //Constant
              borderColor: "#3e95cd",
              fill: false
            }
          ]
        }
      });

      myChart.data.datasets.push({
        data: ['<%= cPrice[i] %>'],
        label: ['<%= name[0] %>'],
        borderColor: "#3e95cd",
        fill: false
      })
           myChart.data.push({
        labels: ['<%= cDate[i] %>']
      })
    </script>
  <% } %>
over 4 years ago · Santiago Trujillo
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