Guest User

Untitled

a guest
Nov 14th, 2018
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.66 KB | None | 0 0
  1. <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
  2.  
  3. <script type="text/javascript">
  4. $(function() {
  5. <?php
  6. $bookingData = array();
  7. $i=0;
  8. foreach($bookingCounts as $booking){
  9. $bookingData[$i]['label'] = $booking['Name'];
  10. $bookingData[$i]['data'] = $booking['total'];
  11. $i++;
  12. }
  13. ?>
  14. var data = <?php echo json_encode($bookingData, JSON_NUMERIC_CHECK);?>;
  15. console.log(data);
  16.  
  17. var options = {
  18. title: 'Booking',
  19. is3D: true,
  20. };
  21.  
  22. var chart = new google.visualization.PieChart(document.getElementById('flot-pie-chart'));
  23. chart.draw(data, options);
  24.  
  25.  
  26. });
  27.  
  28. <div class="flot-chart">
  29. <div class="flot-chart-content" id="flot-pie-chart">
  30. </div>
  31. </div>
  32.  
  33. <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  34.  
  35. document.addEventListener("DOMContentLoaded", function(event) {
  36. /* your code here */
  37. });
  38.  
  39. var data = new google.visualization.DataTable();
  40. data.addColumn('Type', 'ColName');
  41. data.addRows([ <?php PHP ?> ]);
  42.  
  43. <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  44. <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
  45. <script type="text/javascript">
  46. google.charts.load('current', {'packages':['corechart']});
  47. function drawChart(test_input) {
  48. var data = new google.visualization.DataTable();
  49. data.addColumn('string', 'Name');
  50. data.addColumn('string', 'Date');
  51. data.addColumn('number', 'Test_Val_A');
  52. data.addColumn('number', 'Test_Val_B');
  53. data.addRows([
  54. <?php
  55. $dbName = "test_db";
  56. $config = parse_ini_file("myconfigfile.ini",true);
  57. $dbUser = $config["mydb"]["db_user"];
  58. $dbServer = $config["mydb"]["db_ip"];
  59. $dbPassword = $config["mydb"]["db_pass"];
  60.  
  61. $con = mysql_connect($dbServer, $dbUser, $dbPassword);
  62.  
  63. if (!$con) {
  64. die('Could not connect: ' . mysql_error());
  65. }
  66.  
  67. mysql_select_db($dbName, $con);
  68. $sql = mysql_query("SELECT * FROM MyTable where Name like '$test_input'");
  69. $output = array();
  70.  
  71. while($row = mysql_fetch_array($sql)) {
  72. // create a temp array to hold the data
  73. $temp = array();
  74.  
  75. // add the data
  76. $temp[] = '"' . $row['Name'] . '"';
  77. $temp[] = '"' . $row['Date'] . '"';
  78. $temp[] = (int) $row['Test_Val_A'];
  79. $temp[] = (int) $row['Test_Val_B'];
  80. // implode the temp array into a comma-separated list and add to the output array
  81. $output[] = '[' . implode(', ', $temp) . ']';
  82. }
  83. // implode the output into a comma-newline separated list and echo
  84. echo implode(",n", $output);
  85.  
  86. mysql_close($con);
  87. ?>
  88. ]);
  89. var view = new google.visualization.DataView(data);
  90. view.setRows(data.getFilteredRows([
  91. {column: 0, value: test_input}
  92. ]));
  93. view.setColumns([1,2,3]);
  94.  
  95. var options = {
  96. tooltip: {
  97. trigger: 'both',
  98. },
  99. vAxis: { 'title': 'Volume' },
  100. hAxis: { slantedText: true},
  101. crosshair: { trigger: 'both'},
  102. width: 1900,
  103. height: 400
  104. };
  105.  
  106. var chart = new google.visualization.LineChart(document.getElementById('Whatever_my_id_is'));
  107. chart.draw(view, options);
  108. }
  109. </script>
  110.  
  111. <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
  112. <script type="text/javascript">
  113. google.charts.load("current", {packages:["corechart"]});
  114. google.charts.setOnLoadCallback(drawChart);
  115. function drawChart() {
  116. <?php
  117. $bookingData = array();
  118. $i=1;
  119. $bookingData[0][0] = 'Task';
  120. $bookingData[0][1] = 'Hours per Day';
  121. foreach($bookingCounts as $booking){
  122. $bookingData[$i][0] = $booking['Name'];
  123. $bookingData[$i][1] = $booking['total'];
  124. $i++;
  125. }
  126. ?>
  127.  
  128. var data = <?php echo json_encode($bookingData, JSON_NUMERIC_CHECK);?>;
  129. console.log(data);
  130. var data2 = google.visualization.arrayToDataTable(data);
  131.  
  132. var options = {
  133. title: '',
  134. is3D: true,
  135. };
  136.  
  137. var chart = new google.visualization.PieChart(document.getElementById('flot-pie-chart'));
  138. chart.draw(data2, options);
  139.  
  140.  
  141. };
Add Comment
Please, Sign In to add comment