Skip to content
Advertisement

Can’t render two charts on the same page from chart.js

I’ve been trying for the past hour to get Chart.js to render two line charts on the same page. I have ensured that my canvas element IDs are unique, as are my variables.

I am able to successfully load the first chart, ctx or canvas, but not the second chart, ctx2 or canvas2.

This is using chart.js v2.8.0

Here’s the log of errors from inspect element.

Input Data defined in index.html

JavaScript

Chart Drawing in index.html

JavaScript

Canvas elements defined in index.html

JavaScript

Advertisement

Answer

in you data,

JavaScript

you set the yAxisId : 'y-axis-1'. but when you draw the chart, they are id: 'avg-y-axis-1'.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement