Skip to content
Advertisement

Generate an indefinite number of charts as images (chart.js)

I would like to generate several “line charts” as an image file. For this purpose, data is requested from a database. This data is transferred to the function for chart generation separately for each line chart. At the “console.log” output at the beginning of the function, the transferred data is correctly displayed. If I query the same output of the data under “animation: {onComplete: function () {console.log () …}}”, then I only get the data set last queried from the database returned.

In addition, the same string is always output for the image file (regardless of which data is transferred to the function).

JavaScript

Where is my mistake? thx

Advertisement

Answer

I solved the problem by creating a separate canvas object for each chart.

Before the function for creating a chart is called, a new canvas object is created.

JavaScript

“chartcontent” in HTML:

JavaScript
Advertisement