I have the script below which works well, i.e. it generates a chart on the screen when the page loads:
<script type="text/javascript">
google.load("visualization", "1", {packages:["corechart"]});
google.setOnLoadCallback(drawChartAjax);
function drawChartAjax() {
$.ajax({
url: 'json_data.aspx',
type: 'POST',
dataType: 'json',
success: function(data) {
drawChart(data);
}
});
}
function drawChart(json) {
var data = new google.visualization.DataTable();
data.addColumn('string', 'did');
data.addColumn('number', '09/10');
data.addRows(json.length);
var l = json.length, i, x = 0, y = 0;
for(i = 0; i < l; i++) {
data.setValue(y, x, json[i].did); x++;
data.setValue(y, x, json[i].v1); x=0;
y++;
}
var chart = new google.visualization.BarChart( document.getElementById('chart_div') );
chart.draw(data, {width: 300, height: 400, legend: 'bottom', title: 'title goes here'});
}
</script>
What do I have to do to get this to load when a link is clicked?
I know I can display an alert like this:
$(document).ready(function(){
$("a.display_chart").click(function(event){
alert("display the chart");
event.preventDefault();
});
});