You're right, for some reason I ended up thinking you'd need to
generate/destroy rows, while you can just use nulls in place of values
during the shift. Thanks.

You might want to cache the last shifted value, to avoid having to scan the
entire datatable on each 'select' event to unshift it.

Also, I think you want to set the col2 value before erasing col1 value to
null.

Working demo: http://jsfiddle.net/Ry6AA/3/  ( which deselects if you click
on a previously selected item).

-- R.

On 23 September 2011 16:30, asgallant <[email protected]> wrote:

> It shouldn't be that hard to implement:
>
> /*  this adds a 'select' event listner that removes a point
>  *  from column 1 and adds it to column 2 (which changes
>  *  the point's color)
>  *  assumes:
>  *    data is the DataTable object, with data in column 1 and an empty
> column 2
>  *    chart is the Chart object
>  *    options is an object of chart options
>  *  "highlighted" elements that are re-selected stay highlighted
>  *  "highlighted" elements that are not re-selected get returned
>  *  to column 1
>  */
> new google.events.addListener(chart, 'select', function() {
>     // only change if data in column 1 is selected
>     if (data.getSelection()['column'] == 1) {
>         // return previous highlighted elements to column 1
>         for (i = 0, i < data.getNumberOfRows; i++) {
>             if (data.getValue(1, 2) != null) {
>                 data.setValue(i, 1, data.getValue(i, 2));
>                 data.setValue(i, 2, null);
>             }
>         }
>         // add this element to column 2
>         var row = data.getSelection()['row'];
>         data.setValue(row, col, null);
>         data.setValue(row, 2, data.getValue(row, 1));
>         chart.draw(data, options);
>     }
> });
>
> --
> 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/-/hi1UtDbwPK0J.
>
> To post to this group, send email to
> [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/google-visualization-api?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google Visualization API" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-visualization-api?hl=en.

Reply via email to