Thank you for the thoughts. I had read that, and attempted to send a
string in that format. However, when the column is set to type
"string", the string displays as received -> Date(2011,0,1). When
cloumn type is set to "date", the graph will not display. I am not
sure why it is not interpreted as a date (per the GV documentation),
though I assume it may have to do with either the PHP json formatting
or (relatedly) the quotation marks which surround each json element
when encoded.
The workaround I settled on (though it is far from elegant) is to
deliver the information as a string in javascript date notation form
("new Date(2011,0,1)"). In the javascript callback function, I then
do a global replace (removal) of the quotation marks and eval the
remaining json variable. This reads the date string as a javascript
native Date declaration and works correctly.
This approach is less than ideal because it requires special handling
for other variables in the json-encoded PHP response as well.
Please let me know if you have other suggestions, or thoughts on why
the GV documented solution you refer to is not working for me.
On May 8, 7:29 am, MC Get Vizzy <[email protected]> wrote:
> You can send a date with a string of the format "Date(y,m,d)". For
> example, "Date(2011,0,1)" would be January first, 2011. This is addressed
> here:
>
> http://code.google.com/apis/chart/interactive/docs/dev/implementing_d...
>
> <http://code.google.com/apis/chart/interactive/docs/dev/implementing_d...>Though
> I admit it's kind of buried.
>
> On Fri, May 6, 2011 at 4:15 AM, Teliac <[email protected]> wrote:
> > I have a question involving a PHP script that created a json-encoded
> > array and returns it to the client (where it is used to create a
> > DataTable object).
>
> > Is there a way to pass a date value from a php server-side script to
> > the client side GV 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($csvFile, "r")) !== FALSE) {
> > while (($data = fgetcsv($handle)) !== FALSE) {
>
> > // We only need two pieces of data here:
> > // Date (data[0])
> > // EU (data[7])
> > // Add data values to $dt array.
> > $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
> > // be interpreted as type 'date' by GV on client?
> > $dt["rows"][$rc]["c"][0]["v"] = $d;
>
> > // Format data value as float - necessary for GV to recognize
> > as number.
> > $d = $data[7];
> > $d = floatval($d);
> > $dt["rows"][$rc]["c"][1]["v"] = $d;
> > $rc++;
> > }
> > fclose($handle);
> > }
>
> > // Send information back to client via encoded json
> > echo json_encode($dt);
> > ---------
>
> > The above code works as long as I pass the date with column type
> > 'string' (would like column type to be 'date'.
>
> > Thanks in advance for your input.
>
> > --
> > 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.
--
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.