Advertisement
Guest User

Untitled

a guest
Dec 11th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 9.73 KB | None | 0 0
  1.  
  2. <?php
  3. require_once('C:\xampp\htdocs\jpgraph\src\jpgraph.php');
  4. require_once('C:\xampp\htdocs\jpgraph\src\jpgraph_line.php');
  5. require_once('C:\xampp\htdocs\jpgraph\src\jpgraph_bar.php');
  6. $db_host = "localhost";
  7. $db_username = "root";
  8. $db_pass = "";
  9. $db_name = "database";
  10. $datum = date("Y-m-d");
  11. $ev = date("Y");
  12. $honap = date("m");
  13. $nap = date("d");
  14. $ido = date ("H:i:s");
  15. $ora = date("H");
  16. $perc = date("i");
  17. $masodperc = date("s");
  18. $x1_axis = array();
  19. $y1_axis = array();
  20. $x2_axis = array();
  21. $y2_axis = array();
  22. $x3_axis = array();
  23. $y3_axis = array();
  24. $i = 0;
  25. $i1 = 0;
  26. $i2 = 0;
  27. $i3 = 0;
  28.  
  29. //$homerseklet=(rand(10,45));
  30. //echo $homerseklet;
  31. $connection = mysqli_connect("$db_host", "$db_username", "$db_pass", "$db_name") or die ('<p style="color: red; text-align: center">Nem lehet az adatbázishoz csatlakozni </p>'.mysql_error());
  32. echo '<p style="color: green; text-align: center">
  33.    Sikeres csatlakozás az adatbázishoz!
  34. </p>';
  35. $homerseklet1 = $_GET['h1'];
  36. $homerseklet2 = $_GET['h2'];
  37. $homerseklet3 = $_GET['h3'];
  38. $feny = $_GET['feny'];
  39. //$homerseklet1=(rand(10,45));
  40. //$homerseklet2=(rand(10,45));
  41. //$homerseklet3=(rand(10,45));
  42. //$feny=(rand(1,100));
  43. echo 'Elso homero:',$homerseklet1,', ';
  44. echo 'Masodik homero:',$homerseklet2,', ';
  45. echo 'Harmadik homero:',$homerseklet3,', ';
  46. echo 'Fenyerosseg:',$feny;
  47.  
  48. //$db_selected = mysql_select_db('database', $connection);
  49. //if (!$db_selected) {
  50. //    die ('Az adatbazis nem talalhato :/ : ');
  51. //}
  52. //  echo('Az adatbazis kivalasztva');
  53. $sql = "INSERT INTO homerseklet (id, homereseklet1, homerseklet2, homerseklet3, feny, ido, datum, honap, nap, ora, perc, masodperc )
  54. VALUES ('', '$homerseklet1', '$homerseklet2', '$homerseklet3', '$feny', '$ido', '$datum', '$honap','$nap','$ora', '$perc', '$masodperc')";
  55. if ($connection->query($sql) === TRUE) {
  56. echo '<p style="color: green; text-align: center">A hőmérséklet beleett rakva az adatbázisba</p>';
  57. } else {
  58. echo "Error: " . $sql . "<br>" . $connection->error;
  59.  
  60. }
  61.  
  62.  
  63.  
  64. /*
  65. *
  66. *
  67. *
  68. * BEHELYEZES
  69. //$result = mysqli_query($connection,"SELECT * FROM `homerseklet`");
  70. //while($row = $result->fetch_array(MYSQLI_NUM)) {
  71. //    $x1_axis[$i] = $row;
  72. //    echo $x1_axis[$i];
  73. //    $i++;
  74. //  }
  75.  
  76. $result = mysqli_query($connection,"SELECT homerseklet1 FROM homerseklet");
  77. //while($row = $result->fetch_array(MYSQLI_BOTH)) {
  78.  
  79. //    $homerseklet1[$i] =  $row;
  80. //    $i++;
  81. //    }
  82. $query1 = "SELECT * FROM homerseklet ";
  83.  
  84. $homerseklettomb1 = array();
  85. while($row = $result->fetch_array(MYSQLI_ASSOC)) {
  86. $homerseklettomb1[] = $row['id'];
  87. }
  88. */
  89. $SQLCommand = "SELECT * FROM `homerseklet`";
  90. $result = mysqli_query($connection,$SQLCommand);
  91. $homerseklettomb1 = array();
  92. $index = 0;
  93. while($row = mysqli_fetch_assoc($result)){
  94. $homerseklettomb1[$index] = $row['homereseklet1'];
  95. $homerseklettomb2[$index] = $row['homerseklet2'];
  96. $homerseklettomb3[$index] = $row['homerseklet3'];
  97. $fenytomb[$index] = $row['feny'];
  98. $honaptomb[$index] = $row['honap'];
  99. $naptomb[$index] = $row['nap'];
  100. $oratomb[$index] = $row['ora'];
  101. $perctomb[$index] = $row['perc'];
  102. $masodperctomb[$index] = $row['masodperc'];
  103. $index++;
  104. }
  105. echo '===================================<br>';
  106. //print implode(",", $homerseklettomb1);
  107. echo '<br>';
  108. //print implode(",", $homerseklettomb2);
  109. echo '<br>';
  110. //print implode(",", $homerseklettomb3);
  111. echo '<br>';
  112. //print implode(",", $fenytomb);
  113.  
  114.  
  115.  
  116. /*$graph = new graph(800,500);
  117. $graph->img->SetMargin(40,40,40,40);
  118. $graph->img->SetAntiAliasing();
  119. $graph->SetScale("textlin");
  120. $graph->SetShadow();
  121. $graph->title->Set("Example of line centered plot");
  122. $graph->title->SetFont(FF_FONT1,FS_BOLD);
  123.  
  124.  
  125. // Use 20% "grace" to get slightly larger scale then min/max of
  126. // data
  127. $graph->yscale->SetGrace(0);
  128.  
  129.  
  130. $p1 = new LinePlot($y1_axis);
  131. $p1->mark->SetType(MARK_FILLEDCIRCLE);
  132. $p1->mark->SetFillColor("red");
  133. $p1->mark->SetWidth(4);
  134. $p1->SetColor("blue");
  135. $p1->SetCenter();
  136. $graph->Add($p1);
  137. $graph->Stroke();  */
  138. // =====================================================================================================================
  139.  
  140. /*
  141. $graph = new Graph(920,500); // Initialize Graph
  142. $graph->SetScale("intlin");
  143. $graph->SetMargin(80,30,40,50);
  144. $graph->SetMarginColor('white');
  145. $graph->SetFrame(false,'blue',3);
  146. //Set Title Attributes
  147. $graph->title->Set("Egyik cucc");
  148. $graph->yaxis->SetTitleMargin(50);
  149. $graph->title->SetFont(FF_ARIAL,FS_BOLD,12);
  150.  
  151. //Set Subtitle Attributes
  152. $graph->subtitle->Set("Last 24 Hours");
  153. $graph->subtitle->SetFont(FF_ARIAL,FS_BOLD,10);
  154. $graph->subtitle->SetColor('black');
  155. //$graph->xaxis->SetLabelAngle(90);
  156. $graph->xaxis->SetTickLabels($x1_axis);
  157. $graph->xaxis->SetTextLabelInterval(2);
  158.  
  159. // Use Arial font
  160. $graph->xaxis->SetFont(FF_ARIAL,FS_BOLD,9);
  161. $graph->SetAxisLabelBackground(LABELBKG_XAXIS,'orange','red','lightblue','red');
  162. $graph->yaxis->SetFont(FF_ARIAL,FS_BOLD,9);
  163. $graph->xgrid->Show();
  164.  
  165. // Create the plot line
  166. $p1 = new LinePlot($y1_axis);
  167. $p1->value->SetFont( FF_FONT1, FS_BOLD);
  168. $p1->value->SetAlign('center');
  169.  
  170. //Set y-axis title
  171. $graph->yaxis->title->Set("Masik cucc");
  172. $graph->yaxis->SetLabelAlign('right','bottom');
  173.  
  174. $graph->Add($p1);
  175. //print_r($xdata);
  176. $graph->Stroke();  */
  177. ?>
  178. <head>
  179.     <script>
  180.         var homerseklet1_array = [<?php echo '"'.implode('","', $homerseklettomb1).'"' ?>];
  181.         alert(homerseklet1_array[0]);
  182.         var homerseklet2_array = [<?php echo '"'.implode('","', $homerseklettomb2).'"' ?>];
  183.         alert(homerseklet2_array[0]);
  184.         var homerseklet3_array = [<?php echo '"'.implode('","', $homerseklettomb3).'"' ?>];
  185.         alert(homerseklet3_array[0]);
  186.         var feny_array = [<?php echo '"'.implode('","', $fenytomb).'"' ?>];
  187.         alert(feny_array[0]);
  188.         var honap_array = [<?php echo '"'.implode('","', $honaptomb).'"' ?>];
  189.         alert(honap_array[0]);
  190.         var nap_array = [<?php echo '"'.implode('","', $naptomb).'"' ?>];
  191.         alert(nap_array[0]);
  192.         var ora_array = [<?php echo '"'.implode('","', $oratomb).'"' ?>];
  193.         alert(ora_array[0]);
  194.         var perc_array = [<?php echo '"'.implode('","', $perctomb).'"' ?>];
  195.         alert(perc_array[0]);
  196.         var masodperc_array = [<?php echo '"'.implode('","', $mmasodperctomb).'"' ?>];
  197.         alert(masodperc_array[0]);
  198.         homerseklet1_array.toString();
  199.         homerseklet2_array.toString();
  200.         homerseklet3_array.toString();
  201.         feny_array.toString();
  202.         honap_array.toString();
  203.         nap_array.toString();
  204.         ora_array.toString();
  205.         perc_array.toString();
  206.         masodperc_array.toString();
  207.         window.onload = function () {
  208.  
  209.             var chart = new CanvasJS.Chart("chartContainer", {
  210.                 title: {
  211.                     text: "Hőmérséklet és fény Grafikon"
  212.                 },
  213.                 axisX: {
  214.                     valueFormatString: "MMM YYYY"
  215.                 },
  216.                 axisY2: {
  217.                     title: "Hőmérséklet és fényerősség",
  218.                     suffix: "fok"
  219.                 },
  220.                 toolTip: {
  221.                     shared: true
  222.                 },
  223.                 legend: {
  224.                     cursor: "pointer",
  225.                     verticalAlign: "top",
  226.                     horizontalAlign: "center",
  227.                     dockInsidePlotArea: true,
  228.                     itemclick: toogleDataSeries
  229.                 },
  230.                 data: [{
  231.                     type:"line",
  232.                     axisYType: "secondary",
  233.                     name: "Hőmérő #1",
  234.                     showInLegend: true,
  235.                     markerSize: 0,
  236.                     yValueFormatString: "$#,###k",
  237.                     dataPoints: [
  238.                         { x: new Date(2017 , honap_array, nap_array), y:homerseklet1_array}
  239.                     ]
  240.                 },
  241.                     {
  242.                         type: "line",
  243.                         axisYType: "secondary",
  244.                         name: "Hőmérő #2",
  245.                         showInLegend: true,
  246.                         markerSize: 0,
  247.                         yValueFormatString: "$#,###k",
  248.                         dataPoints: [
  249.                             { x: new Date(2017 , honap_array, nap_array), y:homerseklet2_array}
  250.                         ]
  251.                     },
  252.                     {
  253.                         type: "line",
  254.                         axisYType: "secondary",
  255.                         name: "Hőmérő #3",
  256.                         showInLegend: true,
  257.                         markerSize: 0,
  258.                         yValueFormatString: "$#,###k",
  259.                         dataPoints: [
  260.                             { x: new Date(2017 , honap_array, nap_array), y:homerseklet3_array}
  261.                         ]
  262.                     },
  263.                     {
  264.                         type: "line",
  265.                         axisYType: "secondary",
  266.                         name: "Fenymérő #1",
  267.                         showInLegend: true,
  268.                         markerSize: 0,
  269.                         yValueFormatString: "$#,###k",
  270.                         dataPoints: [
  271.                             { x: new Date(2017 , honap_array, nap_array), y:feny_array}
  272.                         ]
  273.                     }]
  274.             });
  275.             chart.render();
  276.  
  277.             function toogleDataSeries(e){
  278.                 if (typeof(e.dataSeries.visible) === "undefined" || e.dataSeries.visible) {
  279.                     e.dataSeries.visible = false;
  280.                 } else{
  281.                     e.dataSeries.visible = true;
  282.                 }
  283.                 chart.render();
  284.             }
  285.  
  286.         }
  287.     </script>
  288. </head>
  289. <body>
  290. <div id="chartContainer" style="height: 370px; width: 100%;"></div>
  291. <script src="https://canvasjs.com/assets/script/canvasjs.min.js"></script>
  292. </body>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement