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_data_source.html#jsondatatable <http://code.google.com/apis/chart/interactive/docs/dev/implementing_data_source.html#jsondatatable>Though I admit it's kind of buried. On Fri, May 6, 2011 at 4:15 AM, Teliac <jschoett...@gmail.com> 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 > google-visualization-api@googlegroups.com. > To unsubscribe from this group, send email to > google-visualization-api+unsubscr...@googlegroups.com. > 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 google-visualization-api@googlegroups.com. To unsubscribe from this group, send email to google-visualization-api+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-visualization-api?hl=en.