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

247
Views
Chart.js - Unable to refresh the page

I have X and Y coordinates that come from a robot. I want to update the chart so that the data is displayed separately as a car moves.

The error throws: Cannot read property "data" of undefined.

Could someone help me, how can i get the upgrade to succeed?

var ros = new ROSLIB.Ros({
    url:'ws://10.0.2.5:9090'
});

var tag5617 = new ROSLIB.Topic({
    ros:ros,
    name:"/dwm1001/tag5617",
    messageType:"dwm1001/anchor"
});

var myChart;
var canvas = document.getElementById('myChart');
var ctx = canvas.getContext('2d');

function init(){
    const myChart = new Chart(ctx, {
        type: 'scatter',
        data: {
            datasets: [{
                label: 'GOKART MOVING',
                data: [{x:1,y:1}], 
                backgroundColor: ['#087037'],   
            }],
        },
        options: {
            scales: {
                yAxes: [{
                    ticks: {
                        beginAtZero: true,
                        suggestedMax: 20,
                    }
                }]
    ,            xAxes: [{
                    ticks:{
                        suggestedMax:15,
                    }
                }]
            }
        }
        });
}
init();

tag5617.subscribe(function(message) {
    //console.log("X: " + message.x);
    //console.log("Y: " + message.y);
    let X = document.getElementById('posX');
    X.innerHTML = message.x.toFixed(2);

    let Y = document.getElementById('posY');
    Y.innerHTML = message.y.toFixed(2);
   
    myChart.data.datasets[0].push({X,Y});
    myChart.update();
});
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You define 2 myChart. So your first declaration stay empty ;) Re-assign your variable, don't make a new who stay in your init function scope.

function init(){
    myChart = new Chart(ctx, {
       ...
    });
}
about 4 years ago · Juan Pablo Isaza Report
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!