Closed 7stud closed 6 years ago
I am also having a problem running the same javascript and html code but my error is Failed to create chart: can't acquire context from the given item
. I have also replaced the code<div id="chart"></div>
with <canvas id="chart"></canvas>
but still the error persists.
@7stud @Souravirus did you try executing your code after the DOM is loaded?
document.addEventListener('DOMContentLoaded', function(){
// your code goes here
}, false);
If you're using turbolinks it may be better to use
document.addEventListener('turbolinks:load', function(){
// your code goes here
}, false);
All this assuming you don't have jquery installed. If you do just use $(document).ready(function(){ /* ... */ });
It actually worked by adding the cdn of the frappe charts @pacuna
It's not clear to me how to setup frappe_charts in rails5. I followed the instructions, but I don't see a chart. I put the following div in one of my views:
Then I used the following chart code taken from https://frappe.github.io/charts/
I put that js in a file called
myjs.js
, and I put myjs.js insideapp/assets/javascripts
.The Web Inspector for Safari 11.0.3 shows the following error:
Line 23 in myjs.js is:
let chart = new Chart({
app/assets/config/manifest.js:
apps/assets/javascripts/application.js:
app/assets/stylesheets/application.js:
Gemfile:
Is the error saying that the DOM hasn't finished loading by the time the js executes so frappe_charts can't find the div? Okay, to test that I tried adding a script tag to my
app/views/layouts/application.html.erb
:and I removed
//= require frappe-charts.min.iife
inapp/assets/javascripts/application.js
. Same error.For a final attempt, I copied the js at the cdn and pasted it in a file and put the file in app/assets/javascripts; and then I coped the css file at the cdn and pasted it in a file and put the file in app/assets/stylesheets; then I deleted the frappe requires from the application.jss and application.css files. Same error.
Not the final attempt. I read a tutorial on yarn and rails5, so I tried installing frappe-charts with yarn. Same error.