The chartAreaGradient function is an exported utility used to create linear gradients for Chart.js line charts. It takes a canvas context, the chart area dimensions, and an array of color stops to return a CSS-compatible gradient object.
Parameters:
ctx: The 2D drawing context of the canvas.chartArea: An object containing the dimensions of the chart area (e.g., top, bottom, left, right).colorStops: An array of objects containing { stop: number, color: string } (where stop is a value between 0 and 1).
If any required parameter is missing or colorStops is empty, it returns 'transparent'.
import { chartAreaGradient } from './path/to/app.js';
// Example usage within a Chart.js configuration
const gradient = chartAreaGradient(ctx, chartArea, [
{ stop: 0, color: 'rgba(255, 0, 0, 0)' },
{ stop: 1, color: 'rgba(255, 0, 0, 1)' }
]);