fxcosta / laravel-chartjs

Simple package to facilitate and automate the use of charts in Laravel 5.x using Chartjs v2 library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Charts Not rendering

Xfaramir opened this issue · comments

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 <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.4.0/Chart.min.js" ></script>
To my scripts.blade.php but cant manage to make it work.

Please help

same problem

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.

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

@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?

Hi @fxcosta, no warnings and errors :(

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.

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.)

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

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!

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>

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.