$(document).ready(function(){
$('#dashboard-chart-type').change(function(){
var selectedVal = $(this).val();
alert(selectedVal);
});
switch(selectedVal) {
case "average":
alert("average");
$('#visualization').empty();
init();
break;
case "total_install":
alert("installs");
$('#visualization').empty();
init2();
break;
case "total_uninstall":
alert("uninstalls");
$('#visualization').empty();
init();
break;
default:
alert("default");
$('#visualization').empty();
init2();
break;
}
});
function init(){
drawColumnComboChart();
}
function init2(){
drawStackedChart();
}
google.load('visualization', '1', {packages: ['corechart']});
function drawColumnComboChart() {
// Create and populate the data table.
var data = google.visualization.arrayToDataTable([
['Month', 'USA', 'UK', 'Germany', 'India', 'China', 'Average'],
['2012/05', 165, 938, 522, 998, 450, 614.6],
['2012/06', 135, 1120, 599, 1268, 288, 682],
['2012/07', 157, 1167, 587, 807, 397, 623],
['2012/08', 139, 1110, 615, 968, 215, 609.4],
['2012/09', 136, 691, 629, 1026, 366, 569.6]
]);
// Create and draw the visualization.
var ac = new google.visualization.ComboChart(document.getElementById('visualization'));
ac.draw(data, {
title : 'Average Installs this year',
width: 600,
height: 400,
vAxis: {title: "Number"},
hAxis: {title: "Month"},
seriesType: "bars",
series: {5: {type: "line"}}
});
}
function drawStackedChart() {
// Some raw data (not necessarily accurate)
var data = google.visualization.arrayToDataTable([
['Month', 'Bolivia', 'Ecuador', 'Madagascar', 'Papua New Guinea', 'Rwanda'],
['2004/05', 165, 938, 522, 998, 450],
['2005/06', 135, 1120, 599, 1268, 288],
['2006/07', 157, 1167, 587, 807, 397],
['2007/08', 139, 1110, 615, 968, 215],
['2008/09', 136, 691, 629, 1026, 366]
]);
// Create and draw the visualization.
var ac = new google.visualization.AreaChart(document.getElementById('visualization'));
ac.draw(data, {
title : 'Monthly Coffee Production by Country',
isStacked: true,
width: 600,
height: 400,
vAxis: {title: "Cups"},
hAxis: {title: "Month"}
});
}