Using data from a an object/JSON

34 views
Skip to first unread message

mrleon83

unread,
Jan 16, 2017, 7:06:07 AM1/16/17
to Google Visualization API
Hi all, I'm trying to use data from JSON (which I've put into an object as I need the key/value pair) to populate the chart.. so far I've been unsuccessful...

Any pointers at all? 


Rit Man

unread,
Jan 16, 2017, 5:41:44 PM1/16/17
to Google Visualization API
 loop through your JSON object and construct the string for each row by concatenating the variables together with the html and echo it so it will be treated as html. Based on the google charts table example this is how i did it in php:
 
(this is a pointer not a working example)


// (html code up until addRows...


data
.addColumn('number', 'Column Name');
data
.addRows([ <? // opening php - no longer in html

$posts
= json_decode($output);
foreach($posts->data as $post) {
   
// populate the variables - code omitted
   echo
"['$message', {v: '$created_time', f: '$formatted_time'}, $shares, $reactions, $comments, $likes],";

// closing php - back to html ?> ]);

var table = new google.visualization.Table(document.getElementById('table_div'));




Reply all
Reply to author
Forward
0 new messages