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

179
Views
How can I create a dynamically assigned variable for a chart with chart.js?

I am trying to create a series of line chart dynamically and then update them once the data has been updated for a particular user in real-time.

I am running into difficulty because I can only get the most recent one to render.

I think this is because when the following code runs it overwrites the ctx variable and I lose the earlier charts.

I tried the following technique with dynamic variables so no two ctx variables would be the same, but it doesn't work.

Thanks in advance for your help.

window['ctx_'+userid] = document.getElementById("forceCurveGraph_"+userid).getContext("2d");
  
     window['myLineChart'+userid] = new Chart(window['ctx_'+userid], {
      type: 'line', data: {
        datasets: [{
          label: "Force Curve",
          data: forcecurvedata, backgroundColor: ['rgba(57,118,251, 0.8)']
        }],
        labels: labels
      }, options: {
        backgroundColor: ['rgba(40, 84, 141, 0.3)'],
        scales: {
          yAxes: [{
            ticks: {
              beginAtZero: true,
              max: graphMax
            }
          }],
          xAxes: [{
            ticks: {
              display: false
            }
          }]
        }
      }
    })
about 4 years ago · Juan Pablo Isaza
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!