Advertisement
Guest User

Untitled

a guest
Mar 21st, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.62 KB | None | 0 0
  1. <!DOCTYPE html>
  2.  
  3. <html>
  4. <head>
  5. <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  6. <meta name="robots" content="noindex, nofollow">
  7. <meta name="googlebot" content="noindex, nofollow">
  8.  
  9. <script type="text/javascript" src="/js/lib/dummy.js"></script>
  10.  
  11. <link rel="stylesheet" type="text/css" href="/css/result-light.css">
  12.  
  13. <style type="text/css">
  14.  
  15. </style>
  16.  
  17. <title>An Example of a Google Bar Chart</title>
  18.  
  19. </head>
  20.  
  21. <body>
  22. <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
  23. <div id="chart_div"></div>
  24.  
  25.  
  26. <script type='text/javascript'>//<![CDATA[
  27.  
  28. google.charts.load('current', {packages: ['corechart', 'line']});
  29. google.charts.setOnLoadCallback(drawBasic);
  30.  
  31. var queryObject="";
  32. var queryObjectLen="";
  33. $.ajax({
  34. type : 'POST',
  35. url : 'getdata2.jsp',
  36. dataType:'json',
  37. success : function(data) {
  38. queryObject = eval('(' + JSON.stringify(data) + ')');
  39. queryObjectLen = queryObject.empdetails.length;
  40. },
  41. error : function(xhr, type) {
  42. alert('server error occoured');
  43. }
  44. });
  45. google.load("visualization", "1", {packages:["corechart"]});
  46. google.setOnLoadCallback(drawChart);
  47. function drawBasic() {
  48.  
  49. var data = new google.visualization.DataTable();
  50.  
  51. data.addColumn('number', 'name');
  52. data.addColumn('number', 'id');
  53.  
  54.  
  55. for(var i=0;i<queryObjectLen;i++){
  56.  
  57. var name = ParseInt(queryObject.empdetails[i].name);
  58. var id = ParseInt(queryObject.empdetails[i].id);
  59.  
  60. data.addRows([
  61. [name,id]
  62. ]);
  63.  
  64. }
  65.  
  66. var options = {
  67. hAxis: {
  68. title: 'Time'
  69. },
  70. vAxis: {
  71. title: 'Popularity'
  72. }
  73. };
  74.  
  75. var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
  76.  
  77. chart.draw(data, options);
  78. }
  79. </script>
  80. </head>
  81. <body>
  82. <div id="chart_div"></div>
  83. </body>
  84. </html>
  85.  
  86. <%@page import="java.sql.*" %>
  87. <%@page import="java.util.*" %>
  88. <%@page import="org.json.JSONObject" %>
  89.  
  90. <%
  91. Connection con= null;
  92. try{
  93. Class.forName("com.mysql.jdbc.Driver").newInstance();
  94. con = DriverManager.getConnection("jdbc:mysql://localhost:3306/java","root","1234");
  95.  
  96. ResultSet rs = null;
  97. List empdetails = new LinkedList();
  98. JSONObject responseObj = new JSONObject();
  99.  
  100. String query = "SELECT * from consumo";
  101. PreparedStatement pstm= con.prepareStatement(query);
  102.  
  103. rs = pstm.executeQuery();
  104. JSONObject empObj = null;
  105.  
  106. while (rs.next()) {
  107. int name = rs.getInt("working_days");
  108. //int empid = rs.getInt("id");
  109. int id = rs.getInt("id");
  110.  
  111. empObj = new JSONObject();
  112.  
  113. empObj.put("name", name);
  114. //empObj.put("empid", empid);
  115. empObj.put("id", id);
  116.  
  117. empdetails.add(empObj);
  118. }
  119. responseObj.put("empdetails", empdetails);
  120. out.print(responseObj.toString());
  121. }
  122. catch(Exception e){
  123. e.printStackTrace();
  124. }finally{
  125. if(con!= null){
  126. try{
  127. con.close();
  128. }catch(Exception e){
  129. e.printStackTrace();
  130. }
  131. }
  132. }
  133. %>
  134.  
  135. {"empdetails":[{"name":20,"id":45},{"name":30,"id":100},{"name":50,"id":150},{"name":10,"id":500},{"name":15,"id":600}]}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement