I am using the react chart js for displaying Line chart.
My gradient background is broken on resize window screen, it becomes black:
How to make it work by changing the size of the screen?
This is the function that creates and generates a gradient:
export const getGradientBackground = (canvas) => {
const ctx = canvas.getContext('2d');
const gradient = ctx.createLinearGradient(
canvas.width / 2,
0,
canvas.width / 2,
canvas.height
);
gradient.addColorStop(0.1, 'rgba(0, 145, 148, 0.15)');
gradient.addColorStop(0.2, 'rgba(0, 145, 148, 0.15)');
gradient.addColorStop(0.3, 'rgba(0, 145, 148, 0.15)');
gradient.addColorStop(0.4, 'rgba(255, 255, 255, 0.15)');
gradient.addColorStop(0.5, 'rgba(255, 255, 255, 0.15)');
gradient.addColorStop(0.6, 'rgba(255, 255, 255, 0.15)');
gradient.addColorStop(0.7, 'rgba(255, 255, 255, 0.15)');
gradient.addColorStop(0.8, 'rgba(255, 255, 255, 0.15)');
gradient.addColorStop(0.9, 'rgba(255, 255, 255, 0.15)');
gradient.addColorStop(1.0, 'rgba(255, 255, 255, 0.15)');
ctx.fillStyle = gradient;
ctx.fillRect(10, 10, 200, 100);
return gradient;
};
Any comment is welcome
