Re: Get and setSelection between chartwrappers

391 views
Skip to first unread message

asgallant

unread,
Jan 5, 2013, 4:15:50 PM1/5/13
to google-visua...@googlegroups.com
You need to get the chart objects to work on from the ChartWrappers, so it would look more like this:

thechartname.getChart().setSelection(thetablename.getChart().getSelection());

which should work, provided that both the chart and table are showing the same rows of data in the same order.  It gets more complicated if they are not.

Your chart that has the min value from grouped data may or may not be able to tie in with other charts, depending on whether or not you can reverse the grouping to find out which row had the min value.  If you can't identify which row had the min value, then you can't tie into the other charts.

On Saturday, January 5, 2013 2:52:13 PM UTC-5, Patryk D wrote:
Hello!
I am trying to achieve same effect as Events  »  Interaction Using Events, but with two chartwrappers - table and barchart. So, choosing a bar in chartwrapper:barchart sets a corresponding row in chartwrapper:table selected. They are both in same dashboard, so I guess it should be possible, yet "thechartname.setSelection(thetablename.getSelection());" is not working. Does anyone have any clue how to fix it? My project may be found here.
I also wanted another chart to do the same thing, but it is a columnchart containing min value of grouped data. Is it possible?
Would be grateful for any advices,
Patryk

Patryk D

unread,
Jan 5, 2013, 4:59:18 PM1/5/13
to google-visua...@googlegroups.com
Thank you for the answer, yet I am still missing something. Current code still doesn't get to the alert:
google.visualization.events.addListener(wykresall, 'select', dothetrick);
function dothetrick(event){
   table.getChart().setSelection(wykresall.getChart().getSelection(event));    
   alert("Event!");
  };
The code: page. Function is lines 330-335, dashboard: 253-255, table: 138-146, barchart: 99-116. They are showing the same data, because they are in the same dashboard. It is in same order, some other function is doing the trick.

asgallant

unread,
Jan 5, 2013, 5:38:36 PM1/5/13
to google-visua...@googlegroups.com
"table" is not defined in your code, did you mean to have "tableall" there?

Patryk D

unread,
Jan 6, 2013, 8:05:16 AM1/6/13
to google-visua...@googlegroups.com
Yes, I did. Stupid mistake :) Still it is not working. The alert is shown, so there is no error, but no row is selected. If any row had been selected before event, it is deselected,

asgallant

unread,
Jan 6, 2013, 11:30:51 AM1/6/13
to google-visua...@googlegroups.com
Add "console.log(wykresall.getChart().getSelection()); to the event listener, open the page in Chrome or Firefox, and see what gets logged in the developer's console when you select something in the chart.

Patryk D

unread,
Jan 6, 2013, 11:55:59 AM1/6/13
to google-visua...@googlegroups.com
[Object]
  1. 0Object
    1. column2
    2. row0
    3. __proto__Object
  2. length1
  3. __proto__Array[0]

Both _proto_ contain multiple categories. I am not really sure what does that mean and what am I looking for.

asgallant

unread,
Jan 6, 2013, 12:18:27 PM1/6/13
to google-visua...@googlegroups.com
It looks like Table visualizations have a problem with setSelection when you pass them an object containing a "column" property.  It looks like it is trying to selection the specific cell in the table, even though selecting cells isn't supported.  Lets try this a slightly different way:

function dothetrick (event) {
    var chartSelection = wykresall.getChart().getSelection();
    var tableSelection = [];
    for (var i = 0; i < chartSelection.length; i++) {
      tableSelection.push({row: chartSelection[i].row});
    }
    tableall.getChart().setSelection(tableSelection);
    alert("Event!");

Patryk D

unread,
Jan 6, 2013, 12:32:21 PM1/6/13
to google-visua...@googlegroups.com
It is working now. Thank you very much for your help and patience! :)

asgallant

unread,
Jan 6, 2013, 12:39:43 PM1/6/13
to google-visua...@googlegroups.com
You're welcome.
Reply all
Reply to author
Forward
0 new messages