Andrew, I can't thank you enough. I had code similar to this on another
page, but it was not working. You have helped me greatly. This makes sense
now. I had assumed that it was in the date format, but I just could not
figure it out.
On Tuesday, June 10, 2014 1:31:14 PM UTC-7, Andrew Gallant wrote:
>
> Your dates are not correct. First, the string should be in the format
> "Date(year, month, day)". Second, javascript uses 0-indexed months (so
> January is 0, not 1), so you have to adjust your data appropriately. Try
> this:
>
> $year = (int) Date('Y', $trans_date);
> $month = (int) Date('m', $trans_date) - 1; // adjust month to javascript's
> 0-index
> $day = (int) Date('d', $trans_date);
> $invArr['rows'][$v] = array(
> 'c' => array(
> array('v' => "Date($year, $month, $day)", 'f' => Date('Y, m, d',
> $trans_date)), // set 'f' to the formatted value of your date, or leave
> out to use default formatting
> array('v' => $data_array[$v]['transqty']),
> )
> );
>
> On Tuesday, June 10, 2014 3:01:42 PM UTC-4, attentionjay wrote:
>>
>> I am attempting to set up a calendar to show volume data. I am receiving
>> an error "q[Ec] is not a function". I am pulling data from a MySql
>> database. The returned data is valid JSON. I cannot get this calendar to
>> show up on the page. The test calendar from the Google page works fine so I
>> know this is something in the data query. The code below is from the
>> calendar page, the php file returning the JSON, the JSON, and the JSON
>> returned and written to the calendar page. Most of the code is directly
>> copied from the Google charts pages. I shortened the JSON quite bit for
>> brevity, but the structure is intact. I show the returned JSON because It
>> may show something that is not correct. I am missing something here. I
>> worked through the date situation with the first column and that no longer
>> gives me an error. if I change the column type to string then it gives me
>> the error that the o axis is not of type date/datetime. I have worked on
>> this too long now and I need help.
>>
>> *Calendar page code:*
>>
>> <script type="text/javascript" src="https://www.google.com/jsapi
>> "></script>
>> <script type="text/javascript">
>>
>> // Load the Visualization API and the proper chart package.
>> google.load("visualization", "1.1", {packages:["calendar"]});
>>
>> // Set a callback to run when the Google Visualization API is loaded.
>> google.setOnLoadCallback(drawCalendar);
>>
>>
>>
>> function drawCalendar() {
>>
>> var jsonData = $.ajax({
>> url: "reporting_data_calendar.php",
>> dataType:"json",
>> async: false
>> }).responseText;
>>
>> // Create our data table out of JSON data loaded from server.
>> var data = new google.visualization.DataTable(jsonData);
>>
>> // Instantiate and draw our chart, passing in some options.
>> var chart = new
>> google.visualization.Calendar(document.getElementById('calendar_div'));
>> chart.draw(data, {width: 1000, height: 400});
>> }
>> </script>
>>
>> <div id="calendar_div" style="position:static; width:1000px;
>> height:400px"></div>
>>
>> *PHP page code:*
>>
>> $invArr = array(
>> 'cols' => array(
>> array('label' => 'TransDate', 'type' => 'date'),
>> array('label' => 'TransQty', 'type' => 'number')
>> )
>> );
>>
>> for($v=0;$v<count($data_array);$v++)
>> {
>> $trans_date = strtotime($data_array[$v]['trans_date']);
>> $formatted_date = Date('Y,m,d',$trans_date);
>> $reg_date = $data_array[$v]["trans_date"];
>>
>> $invArr['rows'][$v] = array(
>> 'c' => array(
>> array('v' => $formatted_date),
>> array('v' => $data_array[$v]['transqty']),
>> )
>> );
>>
>> }
>>
>> header('content-type: application/json');
>> echo json_encode($invArr);
>>
>> *JSON:*
>>
>> {"cols":[{"label":"TransDate","type":"date"},{"label":"TransQty","type":"number"}],"rows":[{"c":[{"v":"2014,03,05"},{"v":"72"}]},{"c":[{"v":"2014,03,07"},{"v":"71"}]},{"c":[{"v":"2014,03,12"},{"v":"94"}]},{"c":[{"v":"2014,06,06"},{"v":"41"}]}]}
>>
>> *JSON as it is returned to the page:*
>> {"cols":[{"label":"TransDate","type":"date"},{"label":"TransQty","type":"number"}],"rows":[{"c":[{"v":"2014,03,05"},{"v":"72"}]},{"c":[{"v":"2014,03,07"},{"v":"71"}]},{"c":[{"v":"2014,03,12"},{"v":"94"}]},{"c":[{"v":"2014,06,06"},{"v":"41"}]}]}
>>
>>
>>
--
You received this message because you are subscribed to the Google Groups
"Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-visualization-api.
For more options, visit https://groups.google.com/d/optout.