Created
March 7, 2012 03:57
-
-
Save jrmoran/1990852 to your computer and use it in GitHub Desktop.
playing with google charts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function drawVisualization() { | |
var col1 = ["AP","AP-PAN","ARENA","CD","CD-PNL","CDU","CDU-FMLN","CDU-PSD","FC","FDR","FDR-CD","FDR-PDC","FDR-PDC-CD","FMLN","FMLN-CD","FMLN-PDC","FMLN-PSD","PAN","PCN","PDC","PDC-FMLN","PDC-FMLN-CD","PDC-PMR-PSD","PDC-PSD","PMR","PMR-PDC","PMR-PDC-PSD-CDU","PMR-PSD","PMR-PSD-CDU","PNL","PPR","PSD"]; | |
var col2 = ["AP","AP-PAN","ARENA","CD","CD-PNL","CDU","CDU-FMLN","CDU-PSD","FC","FDR","FDR-CD","FDR-PDC","FDR-PDC-CD","FMLN","FMLN-CD","FMLN-PDC","FMLN-PSD","PAN","PCN","PDC","PDC-FMLN","PDC-FMLN-CD","PDC-PMR-PSD","PDC-PSD","PMR","PMR-PDC","PMR-PDC-PSD-CDU","PMR-PSD","PMR-PSD-CDU","PNL","PPR","PSD"]; | |
var table1 = [["2003",11990,374,491452,0,0,37629,84995,123,10208,0,0,0,0,471042,0,19739,259,11416,210056,104494,0,0,13105,592,26447,4101,2493,3104,374,0,20419,7773],["2006",0,0,791811,30778,24101,0,0,0,0,0,0,0,0,670711,106314,0,0,0,307330,173982,12192,0,0,0,0,0,0,0,0,2637,0,0],["2009",0,0,867273,25204,0,0,0,0,0,20962,6450,5020,1689,886161,237119,0,0,0,235989,185844,8755,7811,0,0,0,0,0,0,0,0,0,0]]; | |
var table2 = [["2003",0,0,111,0,0,4,6,0,0,0,0,0,0,62,0,6,0,1,52,15,0,0,3,0,0,1,0,0,0,0,1,0],["2006",0,0,147,2,1,0,0,0,0,0,0,0,0,54,4,0,0,0,39,15,1,0,0,0,0,0,0,0,0,0,0,0],["2009",0,0,120,1,0,0,0,0,0,0,1,0,0,76,18,0,0,0,33,10,2,1,0,0,0,0,0,0,0,0,0,0]]; | |
function makeTable(arr1, arr2){ | |
var data = new google.visualization.DataTable(); | |
data.addColumn('string', 'year'); | |
for(var i = 0; i < arr1.length; i++){ data.addColumn('number', arr1[i]); } | |
data.addRows(arr2); | |
return data; | |
} | |
var dataTable1 = makeTable(col1, table1); | |
var dataTable2 = makeTable(col2, table2); | |
var opts ={ | |
width: 900, | |
height: 340, | |
chartArea: { | |
width: 800 | |
}, | |
vAxis:{ | |
logScale: true | |
}, | |
legend:{ | |
position: 'bottom' | |
}, | |
animation:{ | |
duration: 1000, | |
easing: 'out' | |
} | |
}; | |
// Create and draw the visualization. | |
var chart = new google.visualization.ColumnChart(document.getElementById('visualization')); | |
chart.draw(dataTable1,opts); | |
setTimeout(function(){ | |
chart.draw(dataTable2, opts); | |
}, 2000); | |
} | |
| |
// Create and draw the visualization. | |
var chart = new google.visualization.ColumnChart(document.getElementById('visualization')); | |
chart.draw(dataTable1,opts); | |
setTimeout(function(){ | |
chart.draw(dataTable2, opts); | |
}, 2000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment