Timeline Google Charts mysql

146 views
Skip to first unread message

fanny André

unread,
Apr 20, 2016, 3:13:08 AM4/20/16
to Google Visualization API
Bonjour,

Voila j'essai de mettre en place la Timeline Google Charts avec mes données en BDD.
Ce sont des dates de prise de médicament à afficher... Début et fin de prise
J'ai lu la doc de Google mais je n'arrive toujours pas a afficher mon graph....

Est ce que quelqu'un pourrait m'aider ??!
Merci :)
Voila ce que j'ai dans mon fichier :

Code : Tout sélectionner

<script type="text/javascript" src="../js/jquery1.11.3.js"></script>
<script src="https://www.google.com/jsapi" type="text/javascript"></script>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
</head>
<body>
<?php
include_once("../inc/connexion.php");
   $query = $mysqli -> query("SELECT * FROM medicament
   INNER JOIN compte
   ON medicament.cp_id = compte.cp_id
   WHERE compte.cp_id = $id_cp 
   "
);
   $results = array();   
   while($rows = $query -> fetch_array()){
   $results[] = $rows;
   $chart = array();
   foreach($results as $result
   {
   $chart[] = array($result['med_nom'], (int)$result['debut_prise'],(int)$result['fin_prise']);
   }
   $chart = json_encode($chart);
   }   
   echo $chart;
?>


<div id="timeline" style="height: 180px;"></div>

<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
    <script type="text/javascript">
      google.charts.load('current', {'packages':['timeline']});
      google.charts.setOnLoadCallback(drawChart);
      function drawChart() {
        var container = document.getElementById('timeline');
        var chart = new google.visualization.Timeline(container);
        var dataTable = new google.visualization.DataTable();

        dataTable.addColumn({ type: 'string', id: 'med_nom' });
        dataTable.addColumn({ type: 'date', id: 'debut_prise' });
        dataTable.addColumn({ type: 'date', id: 'fin_prise' });
        dataTable.addRows([$chart]);

        chart.draw(dataTable);
      }
    
</script>

Daniel LaLiberte

unread,
Apr 20, 2016, 7:00:17 AM4/20/16
to Google Visualization API
You have to store your $chart data in a JavaScript variable, and the value that you pass to dataTable.addRows() has to be an array of arrays.  I don't know enough php to write that for you, but that should help.

--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualizati...@googlegroups.com.
To post to this group, send email to google-visua...@googlegroups.com.
Visit this group at https://groups.google.com/group/google-visualization-api.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-visualization-api/640f9cb3-bed0-4f88-85d3-64df4df1ca96%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

fanny André

unread,
Apr 20, 2016, 7:12:45 AM4/20/16
to Google Visualization API
Bonjour et merci pour la réponse :)

Mon $chart est justement une variable qui stock mon tableau de dates.
En voici un echo :

[["Vick vaporub","2016-03-16","2016-03-19"],["Actifed","2016-03-10","2016-03-31"],["Aspirine","2016-04-10","2016-04-15"]]


Avez vous une autre idée ?
Merci
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualization-api+unsub...@googlegroups.com.



--
 

Daniel LaLiberte

unread,
Apr 20, 2016, 8:39:40 AM4/20/16
to Google Visualization API
Hi fanny,

The data needs to be in JavaScript, but you have it in php. Converting it to a string in php that represents the JavaScript is one way to do it.  But this message might give you some other ideas:  https://groups.google.com/forum/?utm_medium=email&utm_source=footer#!msg/google-visualization-api/Kw6PI-L7g6Y/PEF8JshrGwAJ


To unsubscribe from this group and stop receiving emails from it, send an email to google-visualizati...@googlegroups.com.



--
 

--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualizati...@googlegroups.com.

To post to this group, send email to google-visua...@googlegroups.com.
Visit this group at https://groups.google.com/group/google-visualization-api.

For more options, visit https://groups.google.com/d/optout.



--

fanny

unread,
Apr 20, 2016, 1:59:56 PM4/20/16
to Google Visualization API
Merci Daniel
Je regarde le lien mais pour l'instant ça ne marche toujours pas....

To unsubscribe from this group and stop receiving emails from it, send an email to google-visualization-api+unsub...@googlegroups.com.



--

--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualization-api+unsub...@googlegroups.com.

To post to this group, send email to google-visua...@googlegroups.com.
Visit this group at https://groups.google.com/group/google-visualization-api.



--
Reply all
Reply to author
Forward
0 new messages