Guest User

Untitled

a guest
Oct 23rd, 2016
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.45 KB | None | 0 0
  1. <script type="text/javascript">
  2.  
  3. // Load the Visualization API and the piechart package.
  4. google.charts.load('current', {'packages':['corechart']});
  5.  
  6. // Set a callback to run when the Google Visualization API is loaded.
  7. google.charts.setOnLoadCallback(drawChart);
  8.  
  9. function drawChart() {
  10.  
  11. var data = new google.visualization.DataTable();
  12.  
  13. data.addColumn('Date', 'X');
  14.  
  15. <?php
  16. /*
  17. $query = ($db->query("SELECT * FROM cubeprice.cubeprice WHERE CubeID = '$id'"));
  18.  
  19. if (!$query->num_rows == 0) //if data exists
  20. {
  21. while($row = $query->fetch_assoc()) //while a row still exists
  22. {
  23. array_push($graphData, array($row["Price"], $row["ShopID"], $row["Date"])); //push ShopID and URL to array
  24. }
  25. }
  26. */
  27. foreach ($price as $key => $values)
  28. {
  29. echo "data.addColumn('number', '" . $values[3] . "');\n";
  30. }
  31.  
  32.  
  33. $graphData = array(); //array to store cube data
  34.  
  35. $query = ($db->query("SELECT Price, MIN(Date) FROM CubePrice WHERE ShopID = 1 and CubeId = '$id'")); //get oldest price for certain cube & shop
  36.  
  37. $row = $query->fetch_assoc();
  38.  
  39. $begin = new DateTime($row["MIN(Date)"]);
  40. $end = new DateTime('now');
  41.  
  42. $interval = DateInterval::createFromDateString('1 day');
  43. $period = new DatePeriod($begin, $interval, $end);
  44.  
  45. foreach ($period as $dateKey => $dt)
  46. {
  47. $tempDate = $dt->format("Y, m, d)");
  48. $JSONDate = "new Date(" . $tempDate;
  49. $MYSQLDate = $dt->format("Y-m-d");
  50. $graphData[$dateKey][0] = $JSONDate;
  51.  
  52. $tempArray = array();
  53.  
  54. foreach($price as $priceKey => $values)
  55. {
  56. $queryString = "SELECT * FROM CubePrice.cubeprice WHERE (Date = '$MYSQLDate' and CubeID = '$id' and ShopID = '$values[0]');";
  57.  
  58. if($query = $db->query($queryString))
  59. {
  60. $row = $query->fetch_assoc();
  61.  
  62. array_push($tempArray, floatval($row["Price"]));
  63. }
  64. }
  65.  
  66. array_push($graphData, $tempArray);
  67. }
  68.  
  69. $json = json_encode($graphData);
  70.  
  71. ?>
  72.  
  73. data.addRows(
  74. <?php
  75. echo $json;
  76. ?>
  77. );
  78.  
  79. var options = {
  80. title: 'Company Performance',
  81. curveType: 'function',
  82. legend: { position: 'bottom' }
  83. }
  84.  
  85. // Instantiate and draw our chart, passing in some options.
  86. var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
  87. chart.draw(data, options);
  88. }
  89.  
  90. </script>
Advertisement
Add Comment
Please, Sign In to add comment