Chartjs-Realtime chart JS in Java obtaining the data from a sensor ;Chart.js: Failed to create chart: can't acquire context from the given item

0👍

Chart.js requires a <canvas> element at initialization. You seem to have known this at some point as you have the right code, but it’s commented out and replaced with a string:

var ctx =  'testChart';
//var ctx = document.getElementById('testChart');

Simply reverse these to make it work:

//var ctx =  'testChart';
var ctx = document.getElementById('testChart');

Of course, you’ll need to ensure the <canvas> element is present in the DOM at runtime.

Leave a comment