Guest User

Untitled

a guest
Jul 9th, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.70 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <script type="text/javascript" src="https://www.google.com/jsapi"></script>
  5. <script type="text/javascript">
  6. google.load('current', {'packages':['corechart']});
  7. google.setOnLoadCallback(drawChart);
  8.  
  9. function drawChart() {
  10. var data = google.visualization.arrayToDataTable([
  11. ['Name', 'RunDate', 'Runs', 'Fails'],
  12. <?php
  13. $dbName = "my_test";
  14. $config = parse_ini_file("myconfig.ini",true);
  15. $dbUser = $config["DB"]["db_user"];
  16. $dbServer = $config["DB"]["db_ip"];
  17. $dbPassword = $config["DB"]["db_pass"];
  18.  
  19. $con = mysql_connect($dbServer, $dbUser, $dbPassword);
  20.  
  21. if (!$con) {
  22. die('Could not connect: ' . mysql_error());
  23. }
  24.  
  25. mysql_select_db($database, $con);
  26.  
  27. $sql = mysql_query("select * from GraphTest");
  28.  
  29. $output = array();
  30.  
  31. while($row = mysql_fetch_array($sql)) {
  32. // create a temp array to hold the data
  33. $temp = array();
  34.  
  35. // add the data
  36. $temp[] = '"' . $row['Name'] . '"';
  37. $temp[] = '"' . $row['RunDate'] . '"';
  38. $temp[] = (int) $row['Runs'];
  39. $temp[] = (int) $row['Fails'];
  40. // implode the temp array into a comma-separated list and add to the output array
  41. $output[] = '[' . implode(', ', $temp) . ']';
  42. }
  43. // implode the output into a comma-newline separated list and echo
  44. echo implode(",n", $output);
  45.  
  46. mysql_close($con);
  47. ?>
  48. ]);
  49.  
  50. // parse the data table for a list of locations
  51. var locations = google.visualization.data.group(data, [0], []);
  52. // build an array of data column definitions
  53. var columns = [1];
  54. for (var i = 0; i < locations.getNumberOfRows(); i++) {
  55. var loc = locations.getValue(i, 0);
  56. columns.push({
  57. label: loc,
  58. type: 'number',
  59. calc: function (dt, row) {
  60. // include data in this column only if the location matches
  61. return (dt.getValue(row, 0) == loc) ? dt.getValue(row, 2) : null;
  62. }
  63. });
  64. }
  65.  
  66. // create a DataView based on the DataTable to get the correct snapshot of the data for the chart
  67. var view = new google.visualization.DataView(data);
  68. // set the columns in the view to the columns we constructed above
  69. view.setColumns(columns);
  70.  
  71. var options = {
  72. title: 'data test',
  73. curveType: 'function'
  74. };
  75.  
  76. var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
  77. // draw the chart using the DataView instead of the DataTable
  78. chart.draw(view, options);
  79. }
  80. </script>
  81. </head>
  82. <body>
  83. <h1> <?=var_dump($output)?> </h1> <!-- prints Array(0) {} -->
  84. <div id="chart_div" style="width: 900px; height: 500px;"></div>
  85. </body>
  86. </html>
  87.  
  88. Not enough columns given to draw the requested chart.×
Add Comment
Please, Sign In to add comment