I have the problem when using chart on the image canvas, the issue is that the chart does not show/appear on the image canvas.
const drawCanvas = (canvasWidth, canvasHeight) => {
const dpr = window.devicePixelRatio || 1;
canvas.width = canvasWidth * dpr;
canvas.height = canvasHeight * dpr;
ctx.scale(dpr, dpr);
ctx.clearRect(0, 0, canvas.width, canvas.height);
const imgAspectRatio = bgImage.width / bgImage.height;
const canvasAspectRatio = canvasWidth / canvasHeight;
let imgWidth, imgHeight;
if (canvasAspectRatio > imgAspectRatio) {
imgHeight = canvasHeight;
imgWidth = imgHeight * imgAspectRatio;
} else {
imgWidth = canvasWidth;
imgHeight = imgWidth / imgAspectRatio;
}
const xOffset = (canvasWidth - imgWidth) / 2;
const yOffset = (canvasHeight - imgHeight) / 2;
ctx.drawImage(bgImage, xOffset, yOffset, imgWidth, imgHeight);
// Function for showing the chart
lineChart(xOffset, yOffset, imgWidth, imgHeight);
};
For the detail code I put it at jsfiddle
JSFIDDLE
I want the chart is showing on the image canvas. Thanks!
6