Piechart Refresh using Jquery

1,178 views
Skip to first unread message

prakar

unread,
Nov 2, 2011, 3:15:06 PM11/2/11
to Google Visualization API
Hi,

I am trying to refresh a pie chart created using google visualization
with the help of jquery but it looks somewhere I am missing something
and its not refreshing the pie chart.

I have a spring controller that returns DataTable in json format.
In my jsp, I am showing the pie chart by calling the controller.

google.load('visualization', '1', {'packages':['corechart']});
$(document).ready(function() {
google.setOnLoadCallback(drawIssueChart);
function drawIssueChart() // Send the query to the data source.
{
$.getJSON('/issuelist/home/chart.jsp', function(response) {
var issueChart = new
google.visualization.PieChart(document.getElementById('issue_chart_div'));
var data = new google.visualization.DataTable(response, 0.6);
issueChart.draw(data, {width: 300, height: 300, title: 'Issue
Chart'});
});
}
}

The above works fine without any issue.

I want to change the pie chart using ajax refresh based on the users
selection of select boxes and clicks a submit button. For that I added
the following code
$('#submit').click(function() {
google.setOnLoadCallback(drawIssueChart);
}

When I click on the submit button, the above code results in Uncaught
Error: Container is not defined in
document.getElementById('issue_chart_div'). I changed the code to pass
the element id to the callback function but still the pie chart is not
showing up and there are no errors also. I am able to confirm that the
calback is getting called.

I greatly appreciate any guidance on how to solve this issue.

Thanks
Prakar

Roni Biran

unread,
Nov 3, 2011, 3:29:16 AM11/3/11
to google-visua...@googlegroups.com
all you need to do is call the drawing function and not the setOnCallback... this is since the google API is already loaded.

try this instead:

$('#submit').click(function() {
       drawIssueChart();
}


Prakar

--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
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.


Reply all
Reply to author
Forward
0 new messages