Limiting the size of a graph

65 views
Skip to first unread message

diferdin

unread,
Dec 17, 2012, 3:08:03 PM12/17/12
to google-visua...@googlegroups.com
Hi all,
Is there a way to limit the size of a data table? Something like myDataTable.setMaxSize()?
I've tried looking at the API reference but obviously saw nothing like it, thought to drop a line.

Thanks in advance to anyone helping with this.

Regards.

Sergey Grabkovsky

unread,
Dec 17, 2012, 4:22:54 PM12/17/12
to google-visua...@googlegroups.com
Hi, I don't understand what you're trying to do, if you could explain more, perhaps I could help you with an alternative. Perhaps you're looking for the DataView, which can present a part of a table?

- Sergey




--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-visualization-api/-/T1PrAhjr-xMJ.
To post to this group, send email to google-visua...@googlegroups.com.
To unsubscribe from this group, send email to google-visualizati...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-visualization-api?hl=en.

diferdin

unread,
Dec 17, 2012, 4:33:59 PM12/17/12
to google-visua...@googlegroups.com
Hi Sergey,
sorry for the confusion, and thanks for your interest.

Long story short: I am building a graph representing the top 10 clients by connection age for my server. As I receive this data in real-time from a push engine, and hence I need to handle additions, removals and cut shifts when the size of the data table exceeds my x, it'd be great if I could specify the size of my data table (i.e. the x) to the size of my rank.

Instead of using data views, I'd rather ensure I keep the data table to a configurable size I want to enforce rather than allow arbitrary length showing parts of it.

Hope this clarifies.

Regards.

Sergey Grabkovsky

unread,
Dec 17, 2012, 4:40:14 PM12/17/12
to google-visua...@googlegroups.com
There's no built in way to do this, but you can accomplish the same thing using the following bit of code:
function dataReceived(data{
  datatable.addRows(data);
  var sizediff datatable.getNumberOfRows(MAX_NUMBER_OF_ROWS;
  if (sizediff 0{
    datatable.removeRows(0sizediff);
  }
}
You can find more information about which methods DataTables have on its reference page.

- Sergey





Regards.

--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.

diferdin

unread,
Dec 17, 2012, 4:58:35 PM12/17/12
to google-visua...@googlegroups.com
I kind of suspected so, and I had looked at the API reference before asking this group. I was just hoping I had overlooked something, but unfortunately it does not look like the case.
It seems as a normal feature to have in a charting library, why is it not there? Would it not be good to have it?

Cheers.

Sergey Grabkovsky

unread,
Dec 17, 2012, 5:14:28 PM12/17/12
to google-visua...@googlegroups.com
This seems like a constraint that the user should enforce, not Google Charts.  I'm not aware of any charting libraries that support what you want.  After all, the user is providing the data to Google; the notion of having the user say "here's my data, but make sure that I've only given you ten rows" is like going out for ice cream and telling them not to sell you too much.

The code I provided will get you the same effect.  Hope it helps!

- Sergey



--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.

diferdin

unread,
Dec 17, 2012, 5:54:46 PM12/17/12
to google-visua...@googlegroups.com
I see your point, but what I am asking is more along the lines of "here's my data, make sure you only chart the first x rows in case I ask you to", which seems a fair option (not a mandatory requirement). The client-side code would become smaller and more elegant -- two desirable features in single-threaded clients such as the web ones. In my case, when my server handles many hundreds of clients I may have to loop over those hundreds although I only need 5 or 10. Yes -- the server should avoid such data exchange, but if clients are fairly volatile that may become necessary.

But anyway, enough of phylantropic talk. Thanks again for your interest.

Regards.

asgallant

unread,
Dec 17, 2012, 6:06:29 PM12/17/12
to google-visua...@googlegroups.com
You can do that with a DataView to restrict the number of rows to 10, so you can have an arbitrarily large DataTable, but still only chart the first 10 rows of data.  Example:

var view new google.visualization.DataView(data);
view.setRows(09);  // use only rows at indices 0-9

Then use the DataView to draw your chart(s) instead of the DataTable.

diferdin

unread,
Dec 17, 2012, 6:11:31 PM12/17/12
to google-visua...@googlegroups.com
Thanks, but as mentioned previously in the thread my use of the data table may involve having thousands of rows, only 5 or 10 of which may be necessary to display. Definitely want to avoid having a hige data table...

Thanks.
Reply all
Reply to author
Forward
0 new messages