Loading...

google-visualization-api@googlegroups.com

[Prev] Thread [Next]  |  [Prev] Date [Next]

Re: [visualization-api] Re: Bar chart freezes if click second time on a bar asgallant Fri Apr 06 07:00:31 2012

Ok, I see what you are talking about.  The "problem" is that the second 
click is "deselecting" the column, so the chart.getSelection() call is 
returning an empty array, which is why you are getting that error.  If you 
clear the selection at the end of your event listener, like this:

google.visualization.events.addListener(chart, 'select', function(){
    alert(chart.getSelection()[0].row);
    chart.setSelection();  // nulls out the selection 
}); 

then you can click the same bar repeatedly without any issues.

On Friday, April 6, 2012 9:12:31 AM UTC-4, Ram wrote:
>
> Thank You  asgallant... I am also tried in Play ground like below 
> coding....I got freezing chart in Playground. Also I got error as " 
> "Uncaught TypeError: Cannot read property 'row' of undefined 
> (retrieve_cache?unique_id=d5541b9085ac908f60fae4763aba5cef3b2fdb30,58)"
>  " 
>
> *My Play ground Code:*
>
>> *
>> *function drawVisualization() {
>>   // Create and populate the data table.
>>   var data = new google.visualization.DataTable();
>>   var raw_data = [['Austria', 1336060, 1538156, 1576579, 1600652, 1968113
>> , 1901067],
>>                   ['Bulgaria', 400361, 366849, 440514, 434552, 393032, 
>> 517206],
>>                   ['Denmark', 1001582, 1119450, 993360, 1004163, 979198, 
>> 916965],
>>                   ['Greece', 997974, 941795, 930593, 897127, 1080887, 
>> 1056036]];
>>   
>>   var years = [2003, 2004, 2005, 2006, 2007, 2008];
>>                   
>>   data.addColumn('string', 'Year');
>>   for (var i = 0; i  < raw_data.length; ++i) {
>>     data.addColumn('number', raw_data[i][0]);    
>>   }
>>   
>>   data.addRows(years.length);
>>   for (var j = 0; j < years.length; ++j) {    
>>     data.setValue(j, 0, years[j].toString());    
>>   }
>>   for (var i = 0; i  < raw_data.length; ++i) {
>>     for (var j = 1; j  < raw_data[i].length; ++j) {
>>       data.setValue(j-1, i+1, raw_data[i][j]);    
>>     }
>>   }
>>   
>>   // Create and draw the visualization.
>>   var chart=new google.visualization.BarChart(document.getElementById(
>> 'visualization'));
>>   chart.draw(data,
>>            {title:"Yearly Coffee Consumption by Country",
>>             width:600, height:400,
>>             vAxis: {title: "Year"},
>>             hAxis: {title: "Cups"}}
>>       );
>>   google.visualization.events.addListener(chart, 'select', function(){
>>     
>>     alert(chart.getSelection()[0].row);  //Alert displayed on First. 
>> Again if i click same bar,Chart Freezes. 
>>   
>>   });
>> }
>
> ‚Äč 
>
> On Fri, Apr 6, 2012 at 6:23 PM, asgallant <[EMAIL PROTECTED]>wrote:
>
>> I plugged that listener code into the Viz playground's BarChart example 
>> (changing "timedata" to "data" to make it compatible), and it worked fine; 
>> it didn't freeze at all.  The problem must be somewhere else in your code, 
>> can you post the code or a link to the page?
>>
>>
>> On Friday, April 6, 2012 7:49:02 AM UTC-4, Ram wrote:
>>>
>>> I have added Click event for each bar in Visualization Bar Chart. If i 
>>> click first time on a Bar, the event triggers and my expected result 
>>> displays properly. But Again if i click on same Bar, event triggers but the 
>>> Chart freezes. After i am not able to interact with chart. My Bar chart 
>>> Click event is given below. Note: i have Bar chart with 4 columns and n 
>>> no.of rows.
>>>
>>>
>>> <https://lh4.googleusercontent.com/-_2QTo7Va1vM/T37XJkpzmmI/AAAAAAAAACs/l0r0e_9jiNI/s1600/6-4-2012+17.4.30+1.jpg>
>>>
>>>
>>> My Click Event: 
>>>
>>> google.visualization.events.**addListener(chart, 'select', function(){
>>>   var row = chart.getSelection()[0].row; *//Chart freezes in this line 
>>> if i click a bar second time
>>> * var column = chart.getSelection()[0].**column;
>>>  var seluser= timedata.getValue(row, 0);
>>>  alert('You selected ' + timedata.getValue(row, 0)); 
>>>  alert(row+","+column); //These lines run properly when click first time 
>>> on Bar in Bar Chart.
>>> });
>>>
>>>
>>>
>>>  -- 
>> 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/-/lxQUCCXPdUgJ.
>>
>> 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.
>>
>
>
>
> -- 
> BY
>
> R.RAMPRASAD
>
> 

-- 
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/-/EIItGo_a8P8J.
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.