Skip to content

chart.js/HTMLCanvasElement compatibility #100

@jorgecf

Description

@jorgecf

Hi:

I have a little express server where I create some chart.js charts using node-canvas implementation of the canvas API. The thing is, Cairo is a real pain and has a long-standing bug where custom fonts just break in Windows Azure machines... which is what I use.

I tried to switch to this library but with little success. ChartJs contructor takes the following parameters:

constructor(
        context: string | CanvasRenderingContext2D | HTMLCanvasElement | ArrayLike<CanvasRenderingContext2D | HTMLCanvasElement>,
        options: Chart.ChartConfiguration
    );

My try was to just pass the context that I can create via:

var img1 = PImage.make(100,50);
var ctx = img1.getContext('2d');
...
new ChartJS(ctx, options)

but this didn't work since this particular context does not implement CanvasRenderingContext2D.canvas property which is required for chartjs.

What I had done with node-canvas is this:

  const canvas1 = createCanvas(1000, 1000);
    const ctx = canvas1.getContext('2d');
...
 new ChartJS(ctx, options)

It works, since that library actually exposes a CanvasRenderingContext2D.canvas (here) class that implements HTMLCanvasElement methods.

Is there a way to work this out? Maybe it's as easy as just providing a HTMLCanvasElement implementation with already existing methods, and I wouldn't mind patching it myself if this library is kind of compatible already.

Thanks in advance😊😊

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions