fxcosta / laravel-chartjs

Simple package to facilitate and automate the use of charts in Laravel 5.x using Chartjs v2 library
486 stars 112 forks source link

Charts Not rendering #50

Open Xfaramir opened 7 years ago

Xfaramir commented 7 years ago

HI !

Unfortunately im trying to run $chartjs->render() passing the variables via the controller but only creates the canvas but not the content.

Is created BUT ->labels ->datasets ->options Are not being render I added To my scripts.blade.php but cant manage to make it work. Please help
rahmatkurnia commented 7 years ago

same problem

fxcosta commented 7 years ago

Can you show a snippet of your code or reproduce or show the error? Check also in the console of your browser if there is any javascript error.

ibrunotome commented 7 years ago

Hi, same problem here. The point is: the error start from nothing, last week works good, today the chart doesn't render, without put the fingers on the code between this weeks. Attached one pic of my console on safari, without errors.

Detail: The charts works well when page doesn't call the chart via ajax, but when calls, i got no render.

Again: works well two weeks ago and stoped from nothing.

I'lll appreciate some help. My config: php7.1 and Laravel 5.4.30.

screenshot 2017-07-30 14 20 21
fxcosta commented 7 years ago

@ibrunotome, this is a strange problem and I could not simulate it in my environment. Are there any warnings or errors displayed on the browser console? Can you post to me?

ibrunotome commented 7 years ago

Hi @fxcosta, no warnings and errors :(

jokaorgua commented 7 years ago

Had the same issue. The problem is in addEventListener('DOMContentLoaded'). For different reasons this event is not fired sometimes(in my case it was ajax request for the chart).

@fxcosta Please think about removing generating chart on DOMContentLoaded

P.S. I see that this event was added as a result of the #39 issue.

jokaorgua commented 7 years ago

As a workaround you can add something like

var DOMContentLoaded_event = document.createEvent("Event"); DOMContentLoaded_event.initEvent("DOMContentLoaded", true, true); window.document.dispatchEvent(DOMContentLoaded_event);

to ajax call AFTER setting html to your divs with chart (works in Chrome at least.)

ibrunotome commented 7 years ago

@fxcosta Do you have time to fix that with the solution above?

fxcosta commented 6 years ago

Has anyone else been successful with this solution? Could you send me a pull request ?? I would be very grateful. I do not have much time lately to study what's going on with this previous event ... I'm sorry!

TesteHD commented 6 years ago

I had the same problem and after a long time I discovered the cause. I was declaring the library like this:

<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.5.0/Chart.min.js"></script>

It was me taking out the "min" and it worked. It was like this.

<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.5.0/Chart.js"></script>

cainytheslave commented 2 years ago

Have the same problem, using Laravel Orchid as admin panel and everthing is lazy loaded with JS so no DOMContentLoaded ever. Would be great to have the option to completely remove this event listener.