Advertisement
Guest User

JSCode

a guest
Jul 3rd, 2012
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.27 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Google Developers</title>
  5. <link rel="stylesheet" type="text/css" href="/css/screen.css" />
  6. <link rel="stylesheet" href="//www.google.com/cse/style/look/default.css" type="text/css" />
  7. <link href='//fonts.googleapis.com/css?family=Open+Sans:300,400' rel='stylesheet' type='text/css'>
  8. <script src="//ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
  9. <script id="jqueryui" src="//ajax.googleapis.com/ajax/libs/jqueryui/1.8.10/jquery-ui.min.js" defer async></script>
  10. <script src="//www.google.com/jsapi?key=AIzaSyCZfHRnq7tigC-COeQRmoa9Cxr0vbrK6xw"></script>
  11. <!--[if lt IE 9]>
  12. <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
  13. <![endif]-->
  14.  
  15. <style type="text/css">
  16.  
  17.  
  18. #side-a {
  19. float: left;
  20.  
  21. }
  22.  
  23. .float-left
  24. {
  25. float: left;
  26. }
  27.  
  28. .float-right
  29. {
  30. float: right;
  31. }
  32.  
  33. .wrapper
  34. {
  35. width: 500px;
  36. }
  37.  
  38. #example2-visualization{
  39. width:500px;
  40. float:left;
  41. }
  42.  
  43. </style>
  44. </head>
  45. <body class="docs framebox_body">
  46.  
  47. <script type="text/javascript" src="https://www.google.com/jsapi"></script>
  48.  
  49. <script type="text/javascript">
  50.  
  51. google.load('visualization', '1.1', {packages: ['corechart']});
  52.  
  53. google.setOnLoadCallback(initialize);
  54.  
  55. function drawExample2() {
  56. // Some raw data (not necessarily accurate)
  57. var rowData1 = [['Month', 'Bolivia', 'Ecuador', 'Madagascar', 'Papua Guinea',
  58. 'Rwanda'],
  59. ['2004/05', 165, 938, 522, 998, 450],
  60. ['2005/06', 135, 1120, 599, 1268, 288],
  61. ['2006/07', 157, 1167, 587, 807, 397],
  62. ['2007/08', 139, 1110, 615, 968, 215],
  63. ['2008/09', 136, 691, 629, 1026, 366]];
  64. var rowData2 = [['Month', 'Bolivia', 'Ecuador', 'Madagascar', 'Papua Guinea',
  65. 'Rwanda'],
  66. ['2004/05', 122, 638, 722, 998, 450],
  67. ['2005/06', 100, 1120, 899, 1268, 288],
  68. ['2006/07', 183, 167, 487, 207, 397],
  69. ['2007/08', 200, 510, 315, 1068, 215],
  70. ['2008/09', 123, 491, 829, 826, 366]];
  71.  
  72. // Create and populate the data tables.
  73. var data = [];
  74. data[0] = google.visualization.arrayToDataTable(rowData1);
  75. data[1] = google.visualization.arrayToDataTable(rowData2);
  76.  
  77. var options = {
  78. width: 800,
  79. height: 600,
  80. vAxis: {title: "Cups"},
  81. hAxis: {title: "Month"},
  82. seriesType: "bars",
  83. series: {5: {type: "line"}},
  84. animation:{
  85. duration: 1000,
  86. easing: 'out'
  87. }
  88. };
  89. var current = 0;
  90. // Create and draw the visualization.
  91. var chart = new google.visualization.ColumnChart(document.getElementById('example2-visualization'));
  92. var button = document.getElementById('example2-b1');
  93. function drawChart() {
  94. // Disabling the button while the chart is drawing.
  95. button.disabled = true;
  96. google.visualization.events.addListener(chart, 'ready',
  97. function() {
  98. button.disabled = false;
  99. button.value = 'Switch to ' + (current ? 'Tea' : 'Coffee');
  100. });
  101. options['title'] = 'Monthly ' + (current ? 'Coffee' : 'Tea') + ' Production by Country';
  102.  
  103. chart.draw(data[current], options);
  104. }
  105. drawChart();
  106.  
  107. button.onclick = function() {
  108. current = 1 - current;
  109. drawChart();
  110. }
  111. }
  112.  
  113. function drawChart() {
  114.  
  115. // Create the data table.
  116. var data = new google.visualization.DataTable();
  117. data.addColumn('string', 'Topping');
  118. data.addColumn('number', 'Slices');
  119. data.addRows([
  120. ['Shanghai', 3],
  121. ['Beijing', 1],
  122. ['Hong Kong', 1],
  123. ['Guangzhou', 1],
  124. ['Shenzhen', 2]
  125. ]);
  126.  
  127. // Set chart options
  128. options = {'title':'Cities',
  129. 'width':400,
  130. 'height':300};
  131.  
  132. // Instantiate and draw our chart, passing in some options.
  133. var chart = new google.visualization.PieChart(document.getElementById('pie_div'));
  134. chart.draw(data, options);
  135. }
  136.  
  137.  
  138.  
  139. function draw(response) {
  140. if (response.isError()) {
  141. alert('Error in query');
  142. }
  143.  
  144. var ticketsData = response.getDataTable();
  145. var chart = new google.visualization.ColumnChart(
  146. document.getElementById('chart_div'));
  147. chart.draw(ticketsData, {'isStacked': true, 'legend': 'bottom',
  148. 'vAxis': {'title': 'Number of taxis'}});
  149.  
  150.  
  151. google.visualization.events.addListener(table, 'select',
  152. function() {
  153. map.setSelection(table.getSelection());
  154. });
  155.  
  156. // Set a 'select' event listener for the map.
  157. // When the map is selected,
  158. // we set the selection on the table.
  159. google.visualization.events.addListener(map, 'select',
  160. function() {
  161. table.setSelection(map.getSelection());
  162. });
  163. }
  164.  
  165.  
  166. function initialize() {
  167. drawExample2();
  168. drawChart();
  169.  
  170. var query = new google.visualization.Query(
  171. 'https://docs.google.com/spreadsheet/ccc?key=0AuehW_PIAYbKdEJ4bHJPNVZYTGRSQ2h5VVk4TTM1VUE');
  172. query.send(draw);
  173. }
  174.  
  175. </script>
  176.  
  177. <form><input id="example2-b1" type="button" value="Switch to Tea"></input></form>
  178.  
  179.  
  180.  
  181.  
  182. <div id="example2-visualization" ></div>
  183. <div id="pie_div" > </div>
  184.  
  185. <div id="chart_div" style="align: center; width: 800px; height: 600px;"></div>
  186. </body>
  187. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement