You might want to consider building a PHP script that will query your
database for you and output the data in the DataTable JSON format (or you
could try out the 3rd-party PHP
library<http://code.google.com/p/mc-goog-visualization/wiki/UserDocumentation>that
implements the Google Query interface).
If you don't want to do either of those, you could make a quick-fix change
to the PHP file to make it accept a parameter via the url and select the
JSON file based on that:
<?php
// get the index of the file to output
$index = $_GET['index'];
// select the file based on $index
switch ($index) {
case 0:
echo file('/path/to/file_0.json');
break;
case 1:
echo file('/path/to/file_1.json');
break;
case 2:
echo file('/path/to/file_2.json');
break;
case 3:
echo file('/path/to/file_3.json');
break;
.
.
.
case n:
echo file('/path/to/file_n.json');
break;
}
?>
You then choose the file to grab like this:
var jsonData = $.ajax({
url: "getData.php?index=3",
dataType: "json",
async: false
}).responseText;
var data = new google.visualization.DataTable(jsonData);
The selector doesn't have to be "index" and it doesn't have to be numeric -
as long as you can map the request from the js end of things to a file on
your server, it will work.
On Thursday, August 16, 2012 6:46:21 PM UTC-4, Chriggi wrote:
>
> Hello,
>
> I have a lot of json-files with different data from my database and want
> to populate my datatables with them. Currently I'm using the method
> described here:
> https://developers.google.com/chart/interactive/docs/php_example
>
> Basically I do this:
>
> var jsonData = $.ajax({
> url: "getData.php",
> dataType:"json",
> async: false
> }).responseText;
> var data = new google.visualization.DataTable(jsonData);
>
> In getData.php there are just these 2 lines:
> $string = file_get_contents("results.json");
> echo $string;
>
> The problem here is, with one .php-file I can only get one JSON. So if i
> have for example 10 different charts with 10 different datatables created
> from different JSONS I need 10 .php-files. Isn't there a better solution
> for this?
>
>
--
You received this message because you are subscribed to the Google Groups
"Google Visualization API" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/google-visualization-api/-/OswCuyyaNasJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-visualization-api?hl=en.