Advertisement
Guest User

Untitled

a guest
May 15th, 2019
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.75 KB | None | 0 0
  1. <html>
  2. <head>
  3. <meta charset="utf-8">
  4. <title>Mereni teplot</title>
  5. <script src="https://www.amcharts.com/lib/3/amcharts.js"></script>
  6. <script src="https://www.amcharts.com/lib/3/serial.js"></script>
  7. <script src="https://www.amcharts.com/lib/3/plugins/export/export.min.js"></script>
  8. <link rel="stylesheet" href="https://www.amcharts.com/lib/3/plugins/export/export.css" type="text/css" media="all" />
  9. <script src="https://www.amcharts.com/lib/3/themes/light.js"></script>
  10. <?php
  11. $servername = "localhost";
  12. $username = "root";
  13. $password = "";
  14. $dbname = "thermometer";
  15.  
  16. // Create connection
  17. $conn = new mysqli($servername, $username, $password, $dbname);
  18. // Check connection
  19. if ($conn->connect_error) {
  20. die("Connection failed: " . $conn->connect_error);
  21. }
  22.  
  23. $sql = "SELECT id, celsius, fahrenheit,TIME_FORMAT( time, '%Y-%m-%d %H:%i') AS timei,(SELECT COUNT(*) FROM temp_log ) AS CountPhp FROM temp_log";
  24. $result = $conn->query($sql);
  25. ?>
  26. <script>
  27. var chartData = generateChartData();
  28. var chart = AmCharts.makeChart("chartdiv", {
  29. "type": "serial",
  30. "theme": "light",
  31. "marginRight": 80,
  32. "autoMarginOffset": 20,
  33. "marginTop": 7,
  34. "dataProvider": chartData,
  35. "valueAxes": [{
  36. "axisAlpha": 0.2,
  37. "dashLength": 1,
  38. "position": "left"
  39. }],
  40. "mouseWheelZoomEnabled": true,
  41. "graphs": [{
  42. "id": "g1",
  43. "balloonText": "[[value]]",
  44. "bullet": "round",
  45. "bulletBorderAlpha": 1,
  46. "bulletColor": "#FFFFFF",
  47. "hideBulletsCount": 50,
  48. "title": "red line",
  49. "valueField": "visits",
  50. "useLineColorForBulletBorder": true,
  51. "balloon":{
  52. "drop":true
  53. }
  54. }],
  55. "chartScrollbar": {
  56. "autoGridCount": false,
  57. "graph": "g1",
  58. "scrollbarHeight": 40
  59. },
  60. "chartCursor": {
  61. "limitToGraph":"g1"
  62. },
  63. "categoryField": "date",
  64. "categoryAxis": {
  65. "parseDates": true,
  66. "axisColor": "#DADADA",
  67. "dashLength": 1,
  68. "minorGridEnabled": true
  69. },
  70. "export": {
  71. "enabled": true
  72. }
  73. });
  74.  
  75. chart.addListener("rendered", zoomChart);
  76. zoomChart();
  77.  
  78. // this method is called when chart is first inited as we listen for "rendered" event
  79. function zoomChart() {
  80. // different zoom methods can be used - zoomToIndexes, zoomToDates, zoomToCategoryValues
  81. chart.zoomToIndexes(chartData.length - 40, chartData.length - 1);
  82. }
  83.  
  84.  
  85. // generate some random data, quite different range
  86. function generateChartData() {
  87. var chartData = [];
  88. <?php
  89. while($row = $result->fetch_assoc()) {
  90. echo "var newDate = new Date();";
  91. echo "newDate.setDate(".$row["timei"].");";
  92. echo $row["id"]. $row["celsius"]. $row["fahrenheit"] ;
  93.  
  94. for (var i = 0; i < 5; i++) {
  95. // we create date objects here. In your data, you can have date strings
  96. // and then set format of your dates using chart.dataDateFormat property,
  97. // however when possible, use date objects, as this will speed up chart rendering.
  98. var newDate = new Date();
  99. newDate.setDate(newDate.getDate());
  100.  
  101. var visits = Math.round(Math.random() * (40 + i / 5)) + 20 + i;
  102.  
  103. chartData.push({
  104. date: newDate,
  105. visits: visits
  106. });
  107. }
  108. }
  109. ?>
  110. return chartData;
  111. }
  112. </script>
  113. <?php
  114. while($row = $result->fetch_assoc()) {
  115. echo "var newDate = new Date();";
  116. echo "newDate.setDate(".$row["timei"].");";
  117. echo $row["id"]. $row["celsius"]. $row["fahrenheit"] ;
  118. }
  119. ?>
  120. <?php
  121. $conn->close();
  122. ?>
  123. <style>
  124. #chartdiv {
  125. width : 100%;
  126. height : 500px;
  127. }
  128. </style>
  129. </head>
  130. <body>
  131. <div id="chartdiv"></div>
  132. </body>
  133. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement