If your data is orderable by the time entered, you can sort the data in 
reverse order by time and put a limit of 5 rows on it.  As an example, if 
column A is a timestamp of the data entry, you can use:

query.setQuery('SELECT A, C, F, H, M ORDER BY A DESC LIMIT 5');

If you need them in the original order, you can use the #sort or 
#getSortedRows methods of the DataTable.

On Thursday, May 30, 2013 2:45:57 PM UTC-4, [email protected] wrote:
>
> Hi am trying to display the data of a Google Spreadsheet in a table with 
> the below code that I have pieced together from the tutorials.
>
> The Google Spreadsheet is updated every day and I only want to show the 
> data from the last five rows.
>
>  <script type="text/javascript" src="http://www.google.com/jsapi
> "></script>
>
>     <script type="text/javascript">
> google.load('visualization', '1', {packages: ['table']});
> var weeklyurl = 'MY - URL';
>     var weeklyVisualization;
>
> function draw() {
>       drawVisualization();
>       drawToolbar();
>     }
>     function drawVisualization() {
>       var query = new google.visualization.Query(weeklyurl);
>       query.setQuery('SELECT A,C,F,H,M');
>
>       query.send(handleQueryResponse);
>     }
>     
>     function handleQueryResponse(response) {
>       if (response.isError()) {
>         alert('Error in query: ' + response.getMessage() + ' ' + 
> response.getDetailedMessage());
>         return;
>       }
>     
>       var data = response.getDataTable();
>       visualization = new 
> google.visualization.Table(document.getElementById('weeklyVisualization'));
>       visualization.draw(data);
>     }
>     function drawToolbar() {
>       var components = [
>        
>         {type: 'html', datasource: weeklyurl},
>         {type: 'csv', datasource: weeklyurl},
>         {type: 'htmlcode', datasource: weeklyurl,
>           gadget: 'http://www.google.com/ig/modules/table.xml'}
>       ];
>     
>       var container = document.getElementById('toolbar_div');
>       google.visualization.drawToolbar(container, components);
>     };
>     
>
>     google.setOnLoadCallback(draw);
>     </script>
>

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to