Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require "conf.php";
- try {
- $conn = new PDO("mysql:host=localhost;dbname=$dbname", $dbuser, $dbpass);
- $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- $result = $conn->query('SELECT date_format(Czas,"%Y") as rok,
- date_format(Czas,"%m")-1 as miesiac,
- date_format(Czas,"%d") as dzien,
- date_format(Czas,"%H") as godzina,
- date_format(Czas,"%i") as minuta,
- temp1 FROM temperatury_log where Czas >= DATE_SUB(NOW(), INTERVAL 1 DAY)');
- $licznik = 0;
- $min = 100; // heheszka taka
- $max = 0;
- $cialko = 'data.addRows([ ';
- foreach ($result as $r) {
- $cialko.='[new Date(' . $r['rok'] . ', ' . $r['miesiac'] . ', ' . $r['dzien'] . ', ' . $r['godzina'] . ', ' . $r['minuta'] . '), ' . $r['temp1'] . '],';
- if ($r['temp1'] > $max) {
- $max = $r['temp1'];
- };
- if ($r['temp1'] < $min) {
- $min = $r['temp1'];
- };
- $licznik++;
- }
- substr_replace($cialko, "", -1);
- $cialko.=']);';
- } catch (PDOException $e) {
- echo 'ERROR: ' . $e->getMessage();
- }
- ?>
- <html>
- <head>
- <!--Load the Ajax API-->
- <script type="text/javascript" src="https://www.google.com/jsapi"></script>
- <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
- <script type="text/javascript">
- google.load('visualization', '1', {packages: ['corechart']});
- google.setOnLoadCallback(drawChart);
- function drawChart() {
- var data = new google.visualization.DataTable();
- data.addColumn('datetime', 'Czaaas');
- data.addColumn('number', 'Temperatura');
- <?php echo $cialko; ?>
- var options = {
- title: 'Temperatury z ostatnich 24 godzin',
- width: 1300,
- height: 400,
- curveType: 'function',
- pointSize: 5,
- hAxis: {
- format: 'HH:mm',
- gridlines: {count: <?php echo $licznik; ?>}
- },
- vAxis: {
- gridlines: {color: 'none'},
- minValue: <?php $min--;echo number_format($min, 0, '', ''); ?>,
- maxValue: <?php $max++;echo number_format($max, 0, '', ''); ?>
- }
- };
- var chart = new google.visualization.AreaChart(document.getElementById('chart_div'));
- chart.draw(data, options);
- }
- </script>
- </head>
- <body>
- <div id="chart_div"></div>
- </body>
- </html>
Add Comment
Please, Sign In to add comment