This is likely not working because taking the responseText from the AJAX
call gives a string, not an array:
var jsonData = $.ajax({
url: "getData.php",
dataType:"json",
async: false
}).responseText;
// jsonData = '[["Datum","Temperatur"],["2014-02-11
12:42:55",21.9],["2014-02-11 12:42:55",21.9],...]';
You need to parse the JSON string before passing it to the arrayToDataTable
method:
var data = new google.visualization.DataTable(JSON.parse(jsonData));
On Friday, February 14, 2014 12:20:43 PM UTC-5, Benedikt Peichel wrote:
>
> Hi
>
> i have connected a mysql db to line chart but it doesn' work: the
> following code i use
>
> <html>
> <head>
> <script type="text/javascript" src="https://www.google.com/jsapi
> "></script>
> <script type="text/javascript" src="//
> ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
> <script type="text/javascript">
> google.load("visualization", "1", {packages:["corechart"]});
>
> google.setOnLoadCallback(drawChart);
>
> function drawChart() {
>
> var jsonData = $.ajax({
> url: "getData.php",
> dataType:"json",
> async: false
> }).responseText;
> var data = new google.visualization.DataTable(jsonData);
>
> var options = {
> title: 'Company Performance',
> curveType: 'function'
> };
>
> var chart = new
> google.visualization.LineChart(document.getElementById('chart_div'));
> chart.draw(data, options);
> }
> </script>
> </head>
> <body>
> <div id="chart_div" style="width: 900px; height: 500px;">Test</div>
> </body>
> </html>
>
>
> <?php
>
> //in der DB suchen
> function getdb($SQL_statement){
> $conn_host="localhost";
> $conn_userid="root";
> $conn_passwd="admin";
> $conn_db="temperaturverlauf";
> $db_conn = mysql_connect($conn_host,$conn_userid,$conn_passwd) or die
> ("Verbindung fehlgeschlagen ".mysql_error());
> mysql_select_db($conn_db,$db_conn);
> $resultset=mysql_query($SQL_statement);
> return $resultset;
> mysql_close();
> }
>
>
> //Letzte 24 Stunden
> $sqlst=getdb("SELECT * FROM asdf LIMIT 0, 30;");
>
> //echo "Daten gelesen";
> $daten = array();
> $daten[0] = array('Datum', 'Temperatur');
> $i = 1;
>
> while($data=mysql_fetch_array($sqlst)){
> $daten[$i] = array($data['datum'], (double) $data['t0']);
> $i = $i + 1;
> }
> $json = json_encode($daten);
> echo $json;
> ?>
>
>
> the php output is:
>
> [["Datum","Temperatur"],["2014-02-11 12:42:55",21.9],["2014-02-11
> 12:42:55",21.9],["2014-02-11 12:42:55",21.8],["2014-02-11
> 12:42:55",21.7],["2014-02-11 12:42:55",21.7],["2014-02-11
> 12:42:55",21.6],["2014-02-11 12:42:55",21.6],["2014-02-11
> 12:42:55",21.5],["2014-02-11 12:42:55",21.4],["2014-02-11
> 12:42:55",21.4],["2014-02-11 12:42:55",21.3],["2014-02-11
> 12:42:55",21.2],["2014-02-11 12:42:55",21.2],["2014-02-11
> 12:42:55",21.1],["2014-02-11 12:42:55",21.1],["2014-02-11
> 12:42:55",21],["2014-02-11 12:42:55",20.9],["2014-02-11
> 12:42:55",20.9],["2014-02-11 12:42:55",20.8],["2014-02-11
> 12:42:55",20.7],["2014-02-11 12:42:55",20.7],["2014-02-11
> 12:42:55",20.6],["2014-02-11 12:42:55",20.6],["2014-02-11
> 12:42:55",20.5],["2014-02-11 12:42:55",20.4],["2014-02-11
> 12:42:55",20.4],["2014-02-11 12:42:55",20.3],["2014-02-11
> 12:42:55",20.2],["2014-02-11 12:42:55",20.2],["2014-02-11 12:42:55",20.1]]
>
>
>
> an the output is table has no data, what is wrong?
>
> thank's!!
>
--
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-visualization-api.
For more options, visit https://groups.google.com/groups/opt_out.