1👍
The problem is most likely that you have the chart inside a template, which causes it not to be rendered in the moment that you are running the jQuery selector and constructing the chart.
jQuery will always return a value even if no objects have been found. So your check will always say that a context has been found. To fix this, you have to check the length
of the jQuery result:
var ctx = $("#groupPerformanceChart");
if (ctx.length <= 0) {
console.log("Context not available");
return;
}
else {
console.log("Context available", ctx)
}
Source:stackexchange.com