Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

517
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!