cmen / CMENGoogleChartsBundle

This Bundle provides a Twig extension and PHP objects to display Google charts in your Symfony application.
https://developers.google.com/chart/
Other
75 stars 21 forks source link

CalendarChart : "n.getFullYear is not a function error" with example datas #32

Closed L0kidor closed 5 years ago

L0kidor commented 5 years ago

I, trying to setup a calendar chart. I begin by copying pasting the example provided in the doc but not working. Got the error mentioned in the title. Did I forget any include statement or whatever ?

cmen commented 5 years ago

This example works for me. Did you correctly include the library in your template ?

https://github.com/cmen/CMENGoogleChartsBundle/blob/master/Resources/doc/basic_usage.md#case-1--one-chart

<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>

(test with last stable version of Google chart and last version of this bundle)

L0kidor commented 5 years ago

I did, many other charts works fine. My config :

cmen_google_charts: version: "current" language: "fr"

And the template

`

<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
    {{ gc_draw(statsAnnuelles, 'div_chart') }}
</script>`

In my controller, i return that :

return $this->render('statistiques/annuelles.html.twig', array("statsAnnuelles" => $pieChart));

cmen commented 5 years ago

Could you inspect the code with your browser and send me the generated Javascript for this chart ?

L0kidor commented 5 years ago

yep, here it is :

`

`

The console doesn't show any error.

cmen commented 5 years ago

You have format errors for dates "This value is not a valid datetime.".

Here my version :

google.visualization.arrayToDataTable([[{"label":"Date","type":"date"}, {"label":"Attendance","type":"number"}], 
[new Date(2012, 2, 13, 00, 00, 00), 37032], 
[new Date(2012, 2, 14, 00, 00, 00), 38024], 
[new Date(2012, 2, 15, 00, 00, 00), 38024], 
[new Date(2012, 2, 16, 00, 00, 00), 38108], 
[new Date(2012, 2, 17, 00, 00, 00), 38229], 
[new Date(2012, 2, 18, 00, 00, 00), 38177], 
[new Date(2012, 2, 19, 00, 00, 00), 38705], 
[new Date(2012, 2, 20, 00, 00, 00), 38210], 
[new Date(2012, 2, 21, 00, 00, 00), 38029], 
[new Date(2012, 2, 22, 00, 00, 00), 38823], 
[new Date(2012, 2, 23, 00, 00, 00), 38345], 
[new Date(2012, 2, 24, 00, 00, 00), 38436], 
[new Date(2012, 2, 25, 00, 00, 00), 38447]], false);

You should check date values passed into method setArrayToDataTable.

L0kidor commented 5 years ago

mhhh

I used values mentionned here.

I will try to change that.

L0kidor commented 5 years ago

Got it !

In the example the dates are passed like that : [ new DateTime('2012-03-13'), 37032 ], wich is interprated as Symfony\Component\Validator\Constraints\DateTime.

Adding \ before datetime make it interpreted as php dateTime: [ new \DateTime('2012-03-13'), 37032 ],

And that works fine.

Thanks for supporting.

cmen commented 5 years ago

:+1: