line chart to only display the last "X" number of lines

36 views
Skip to first unread message

Dave-in-NJ

unread,
Jul 15, 2018, 1:48:00 PM7/15/18
to Google Visualization API
I automatically insert a line in Google Sheets, then my data on that line.
this keeps pushing the last line of the chart.
after a month, the line chart is so compressed as to not be very easy to pick out the latest data.


I am totally raw, the veriest tyro to  Sheets and Charts, so this may be basic stuff.

if there a way to set the chart axies to be the newest line through the last 500 lines ?

I have an inkling that it might be easier to just use the first 500 lines, and insert a new line at the top of the Sheet.  then to have the X axis display in reverse order from oldest to newest.

Ray Thomas

unread,
Jul 17, 2018, 8:19:50 PM7/17/18
to Google Visualization API
It would be nice if there was a query that could do this when the Sheet is first read, but as far as I know there is not. One solution is to download all the data then work on the datatable before you display it. The methods that can be used are at https://developers.google.com/chart/interactive/docs/reference#methods

One method that can be used is to find the number of rows in the datatable using .getNumberOfRows(), then a little math and use .removeRows(rowIndex,numberOfRows)

The code then becomes:

var dataTable = response.getDataTable();
num = dataTable.getNumberOfRows()
dataTable.removeRows(0, num - 30)

I have a Google Sheet that contains a little under 4,000 rows, and used this method to just show the last 30. An example file is at http://brisray.com/test/google-dave.htm to show you it working.

Ray
Reply all
Reply to author
Forward
0 new messages