Thank you so much! It works!
Den onsdag den 16. april 2014 00.47.32 UTC+2 skrev Karsten Tietje:
>
> Hi
>
> I'm trying to create a chart from a sql query which gets encoded into
> json. I'm quite certain that my json format is correct:
>
>
> [["Dato","Kilo"],["04-14",90],["04-15",90],["04-14",85],["04-15",85],["04-14",10],["04-15",10],["04-14",12],["04-15",12]]
>
>
>
> SQL and PHP code:
>
> <?php
> global $wpdb;
> $user_ID = get_current_user_id();
>
> $sql="SELECT $wpdb->postmeta.meta_value as Kilo,
> $wpdb->posts.post_date as Dato FROM $wpdb->posts, $wpdb->postmeta
> WHERE post_type = 'workout'
> AND post_author = $user_ID
> AND meta_key = 'vægt'
> AND post_status = 'publish'
> ";
>
> $posts = $wpdb->get_results($sql);
>
>
>
> $result = mysql_query($sql);
> $num = mysql_num_rows($result);
> # set heading
> $data[0] = array('Dato','Kilo');
> for ($i=1; $i<($num+1); $i++)
> {
> $data[$i] = array(substr(mysql_result($result, $i-1, "Dato"), 5, 5),
> (int) mysql_result($result, $i-1, "Kilo"));
> }
> echo json_encode($data);
>
>
> ?>
>
>
> Google chart code:
>
> <script type="text/javascript" src="https://www.google.com/jsapi"></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 obj = window.JSON.stringify(jsonData);
> var data = google.visualization.arrayToDataTable(obj);
>
> var options = {
> title: 'Test'
> };
>
> var chart = new google.visualization.LineChart(
> document.getElementById('chart_div'));
> chart.draw(data, options);
> }
>
> </script></head>
>
> <div id="chart_div" style="width: 900px; height: 500px;"></div>
>
>
> The chart is simply not showing up, and I can't figure out why. Any
> suggestions?
>
>
>
>
>
>
>
--
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/d/optout.