Re: Pie chart : When I click an already selected slice, everything does stop!!!

53 views
Skip to first unread message

asgallant

unread,
Oct 16, 2012, 1:24:58 PM10/16/12
to google-visua...@googlegroups.com
When you click on an already selected slice, the slice is removed from the selection, so when you call the getSelection method, it returns an empty array.  Attempting to access a property of an element in an empty array will throw an exception.  There are two ways you can handle this.

1) you can test to see whether anything is selected before trying to use the selected value, ie:

function selectEvent1({
    var selection chart1.getSelection();
    if (selection.length 0{
        selected_data data1.getValue(selection[0].row0);
        change_department(selected_data);
    }
}

2) you can unset the selection after doing all your processing.  This will ensure that when a user clicks a slice, there will always be a selected element:

function selectEvent1({
    selected_data data1.getValue(chart1.getSelection()[0].row0);
    change_department(selected_data);
    // calling setSelection with no parameters clears the chart's selections
    chart1.setSelection();
}

On Tuesday, October 16, 2012 12:55:25 PM UTC-4, Sangkeun Park wrote:
...
...
chart1.draw(data1);
function selectEvent1() {
selected_data = data1.getValue(chart1.getSelection()[0].row, 0);
change_department(selected_data);
}
google.visualization.events.addListener(chart1, 'select', selectEvent1);

--------------------------------------------------------------------------------------------------------

When I click pie-chart it works very well, it call change_Department function with parameter.
However, if I click the already clicked(selected) slice, everything stops!! no work. freezing...
If I remove the first line in the function selectEvent1(), clicking selected slice doesn't matter. pie-chart is clickable again although I click selected slice.

What I wanna do is that if I click selected slice, then I want to make the slice unselected. 
What can I do for it?

Sangkeun Park

unread,
Oct 16, 2012, 9:16:29 PM10/16/12
to google-visua...@googlegroups.com

First one is exactly what I want to do.
It works very well,
I appreciate it!

2012년 10월 17일 수요일 오전 1시 55분 25초 UTC+9, Sangkeun Park 님의 말:
Reply all
Reply to author
Forward
0 new messages