Skip to content
Advertisement

Error: Failed to create chart: can’t acquire context from the given item

So, i have downloaded a bootstrap template and i’m trying to change the data of the charts using js: So the html:

JavaScript

JS:

JavaScript

But i get in the console this error:

Failed to create chart: can’t acquire context from the given item

and no data show up in the chart. The original javascript code from the template in main.js file:

JavaScript

The template that im using: https://demo.dashboardpack.com/architectui-html-pro/dashboards-minimal-1.html

Advertisement

Answer

Based on the template you mentioned, and your chart syntax, it seems you’re using an “ApexCharts” chart. Although I can’t see which version the template uses, I reproduced it with the following changes to your code:

  • Included the latest ApexCharts library CDNs here: https://cdnjs.com/libraries/apexcharts
  • Removed the “#” from GetElementById.
  • Renamed the Chart() call to ApexCharts() (this naming might be specific to your template, so you might not need to do this)
  • Called myChart.render(); at the end.

You can see it working here: https://jsfiddle.net/espriella/r0yva4ug/4/

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