SeanSobey / ChartjsNodeCanvas

A node renderer for Chart.js using canvas.
MIT License
230 stars 79 forks source link

Image quality (2) #94

Closed TimHav closed 2 years ago

TimHav commented 2 years ago

Describe the bug Be able to pass the render quality to the different render functions.

In this similar issue, the requestor was advised to scale up the canvas to get a higher resolution image. This works, but has as drawback that the texts in the graph are not scaled accordingly.

However, node-canvas supports passing image quality as a parameter, so this package can expose that in its API.

Versions

TimHav commented 2 years ago

Another solution for this problem is to pass the devicePixelRatio as an option when generating an image. Do not set the devicePixelRatio higher when rendering on screen when you care about your animation performance. https://www.chartjs.org/docs/latest/configuration/device-pixel-ratio.html

SeanSobey commented 2 years ago

It sounds like what you are after is increasing the font size, you should not need devicePixelRatio (and probably avoid it as it can cause other issues). Use canvas size to render the image at the resolution you plan to use, and increase the various font sizes as you need.

That said I am adding support for the mentioned APIs anyway. It may be useful for some applications but in most cases the defaults are fine.

brandonsturgeon commented 10 months ago

Is that branch dead? Seems like exactly what I'm looking for.

samuelkilada commented 9 months ago

@brandonsturgeon If you want to increase the quality, the above "devicePixelRatio" is the way to do it. Just do this in your "options" configuration (the same place where you put scales, etc.):

options: { devicePixelRatio: 2, // this doubles the default quality of 1 scales: { ... } }

I tried this out and the quality is so much better!