Advertisement
Guest User

Untitled

a guest
Mar 27th, 2015
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.84 KB | None | 0 0
  1. chart7.draw(arrdata, option7);
  2. chart8.draw(arrdata1, option8);
  3.  
  4. google.load('visualization', '1.0', {'packages':['corechart']});
  5. google.setOnLoadCallback(RequestData);
  6.  
  7. function RequestData()
  8. {
  9. var dataString ={"Id": 1, "Value" : 30 };
  10. var dataString1 ={"Id": 2, "Value" : 30 };
  11. $.ajax
  12. (
  13. {
  14. type : 'GET',
  15. // asynch :'false',
  16. data: dataString,
  17. url : 'http://localhost:8080/Charts/db',
  18. success : function(data)
  19. {
  20. var queryObject="";
  21. var queryObjectLen="";
  22.  
  23. alert("success");
  24. queryObject = jQuery.parseJSON(data);
  25. queryObjectLen = queryObject.Details.length;
  26. console.log("queryObj: "+queryObject+" Length: "+queryObjectLen);
  27. // start of drawchart()
  28. drawChart(queryObject, queryObjectLen);
  29.  
  30. },
  31. error : function(xhr, type)
  32. {
  33.  
  34. alert('server error occoured')
  35. }
  36. })
  37.  
  38. $.ajax
  39. (
  40. {
  41. type : 'GET',
  42. //asynch :'false',
  43. data: dataString1,
  44. url : 'http://localhost:8080/Charts/db',
  45. success : function(data)
  46. {
  47. var queryObject="";
  48. var queryObjectLen="";
  49.  
  50. alert("success");
  51. queryObject = jQuery.parseJSON(data);
  52. queryObjectLen = queryObject.Details.length;
  53. console.log("queryObj: "+queryObject+" Length: "+queryObjectLen);
  54. // start of drawchart()
  55. drawChart(queryObject,queryObjectLen);
  56.  
  57.  
  58. },
  59. error : function(xhr, type)
  60. {
  61.  
  62. alert('server error occoured')
  63. }
  64. })
  65.  
  66. }
  67.  
  68.  
  69. function drawChart(queryObject, queryObjectLen)
  70. {
  71.  
  72. console.log("Inside drawChart()");
  73. var arrdata = new google.visualization.DataTable();
  74. arrdata.addColumn('number', 'Id');
  75. // arrdata.addColumn('String', 'PatientName');
  76. //arrdata.addColumn('String', 'Department');
  77. arrdata.addColumn('number', 'Value');
  78. for(var i=0; i<queryObjectLen; i++)
  79. {
  80. //console.log(queryObject.Details[i].DeptName);
  81. var Id= queryObject.Details[i].Id;
  82. var PatientName = queryObject.Details[i].PatientName;
  83. var Department = queryObject.Details[i].Department;
  84. var Value = queryObject.Details[i].Value;
  85. arrdata.addRows([
  86. [parseInt(Id),parseInt(Value)]
  87. ]);
  88. }
  89. var options = {
  90. title: 'Id v/s val on vertical axis',
  91. vAxis: {title: 'Id', titleTextStyle: {color: 'red'}},
  92. 'width':400,
  93. 'height':300
  94. };
  95. var option2 = {
  96. title: 'Id V/s Val on horiontal axis',
  97. hAxis: {title: 'Id', titleTextStyle: {color: 'blue'}},
  98. 'width':400,
  99. 'height':300
  100. };
  101.  
  102. var option3 = {
  103. title: ' Pie Chart',
  104. 'width':400,
  105. 'height':300
  106. };
  107. var option4 = {
  108. title: ' Line Chart',
  109. 'width':400,
  110. 'height':300
  111. };
  112. var options5 = {
  113. title: 'Id v/s val on vertical axis',
  114. vAxis: {title: 'Id', titleTextStyle: {color: 'red'}},
  115. 'width':400,
  116. 'height':300
  117. };
  118. var option6 = {
  119. title: 'Id V/s Val on horiontal axis',
  120. hAxis: {title: 'Id', titleTextStyle: {color: 'blue'}},
  121. 'width':400,
  122. 'height':300
  123. };
  124.  
  125. var option7 = {
  126. title: ' Pie Chart',
  127. 'width':400,
  128. 'height':300
  129. };
  130. var option8 = {
  131. title: ' Line Chart',
  132. 'width':400,
  133. 'height':300
  134. };
  135. var chart = new google.visualization.BarChart(document.getElementById('chart_div'));//this is altogether a different object
  136. var chart2 = new google.visualization.ColumnChart(document.getElementById('chart_div2'));
  137. var chart3 = new google.visualization.PieChart(document.getElementById('chart_div3'));
  138. var chart4 = new google.visualization.LineChart(document.getElementById('chart_div4'));
  139. var chart5= new google.visualization.BarChart(document.getElementById('chart_div5'));
  140. var chart6 = new google.visualization.ColumnChart(document.getElementById('chart_div6'));
  141. var chart7 = new google.visualization.PieChart(document.getElementById('chart_div7'));
  142. var chart8 = new google.visualization.LineChart(document.getElementById('chart_div8'));
  143. chart.draw(arrdata, options);
  144. chart2.draw(arrdata, option2);
  145. chart3.draw(arrdata, option3);
  146. chart4.draw(arrdata, option4);
  147. chart5.draw(arrdata1, options5);
  148. chart6.draw(arrdata1, option6);
  149. chart7.draw(arrdata1, option7);
  150. chart8.draw(arrdata1, option8);
  151. }
  152.  
  153.  
  154. </script>
  155. </head>
  156.  
  157. <body>
  158. <div id="chart_div" style="width: 400px; height: 300px;"></div>
  159. <div id="chart_div2" style="width: 800px; height: 400px;"></div>
  160. <div id="chart_div3" style="width: 400px; height: 300px;"></div>
  161. <div id="chart_div4" style="width: 400px; height: 500px;"></div>
  162.  
  163. <div id="chart_div5" style="width: 400px; height: 300px;"></div>
  164. <div id="chart_div6" style="width: 800px; height: 400px;"></div>
  165. <div id="chart_div7" style="width: 400px; height: 300px;"></div>
  166. <div id="chart_div8" style="width: 400px; height: 500px;"></div>
  167. </body>
  168. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement