I am trying to draw a rectangle on a container using JavaScript, however I keep encountering the below error:
canvas.getContext is not a function
Please see the JavaScript I am using:
console.log("START");
var canvas = document.getElementById($parameters.Id);
console.log(canvas);
var ctx = canvas.getContext("2d");
console.log(ctx);
ctx.fillStyle = "#FF0000";
ctx.fillRect(0, 0, 150, 75);
console.log("END");
I pass in the container id, which from the log I can see is passed successfully. Has anyone got a suggestion as to where I have gone wrong in the code?
Hi Roisin,
a container becomes a <div> element in the dom, but what you want is a <canvas> element.
So you can use the html widget with tag canvas on your screen, or you can add the canvas element with javascript inside your container.
see attached oml for both options
Dorine
This works perfectly! Thank you for example and explanation :)