I have a question involving a PHP script that is creating a json-
encoded DataTable object.
Is there a way to pass a date value from a php server-side script to
the client side Google Visualization JavaScript such that it is
recognized by the DataTable object as a 'date' type?
Some details:
The php script creates a json encoded array that is requested from
(and returned to) the client via a jQuery ajax call. The code looks
like this:
----------
// DataTable object.
$dt = array();
// Column information
$col_ids = array("DATE","EU");
$col_labels = array("Date","Equity Utilization");
$col_types = array("string","number"); // <- Would like to pass as
"date" rather than "string"
// Populate DataTable object with column information.
for ($y = 0; $y < count($col_ids); $y++) {
$dt["cols"][$y]["id"] = $col_ids[$y];
$dt["cols"][$y]["label"] = $col_labels[$y];
$dt["cols"][$y]["type"] = $col_types[$y];
}
// Get data from csv file and populate DataTable rows.
$rc = 0;
if (($handle = fopen($g_accountFile, "r")) !== FALSE) {
while (($data = fgetcsv($handle)) !== FALSE) {
// We only need two pieces of data here:
// Date (data[0])
// EU (data[7])
// Add data value to DataTable object.
$d = $data[0];
// $d is the date as a string, would like it to be interpreted
as
// type 'date' when read in by DataTable call on client.
// Is it possible to parse it here, or otherwise format the
string to
$dt["rows"][$rc]["c"][0]["v"] = $d;
// EU needs to be a number (float) format.
$d = $data[7];
$d = floatval($d);
$dt["rows"][$rc]["c"][1]["v"] = $d;
$rc++;
}
fclose($handle);
}
// Send information back via properly encoded json
echo json_encode($dt);
---------
The above code works as long as I pass the date as a type 'string'
--
You received this message because you are subscribed to the Google Groups
"Google Visualization API" group.
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.