Hallo zusammen
Ich bin seit längerem an einem Projekt mit Highcharts. Ich messe mit einem Sensor den Luftdruck, schreibe diesen anschliessend in eine Datenbank und stelle schliesslich alle Messwerte in einem Diagramm von Highcharts dar. Dazu habe ich zwei php-Files. Das eine File (P_INNEN_data.php) stellt eine Art Tabelle mit den Messwerten dar, welche dann an das andere File geschickt wird. Dieses zweite File (P_INNEN.php) ist zuständig für die Darstellung des Diagramms.
Dies funktioniert soweit.
Nun will ich aber die SensorID vom Sensor im P_INNEN.php festlegen und beim zweiten File als Variable einfügen. Dann soll das P_INNEN_data.php-File die Tabelle darstellen und diese an P_INNEN.php zurücksenden. Diese Übergabe der Tabelle funktioniert jedoch nicht reibungslos.
Ich bin dort hängen geblieben und bitte jetzt die Profis unter euch um Hilfe, oder alle, die sich damit auskennen!
Vielen Dank im Voraus!
Hier die zwei Files. Ich habe versucht, das wesentliche mit Kommentaren auszuschmücken.
Falls ihr weitere Unterlagen benötigt, dann lasst es mich wissen!
P_INNEN.php:
PHP
- <?php
- $x = 'P_INNEN'; //Hier wird die SensorID definiert
- echo "<a href='P_INNEN_data.php?x=$x'>Hier klicken</a>"; //Übergabe der SensorID an das andere File
- ?>
- <!DOCTYPE HTML>
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
- <title>AZ Elektronik, Berlin</title>
- <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
- <script type="text/javascript">
- $(function() {
- $.getJSON("P_INNEN_data.php", function(data) { //Aufrufen der dargestellten Tabelle vom anderen File
- //(Alles innerhalb des $.getJSON{} wurde getestet und muss nicht beachtet werden.
- // Create a timer
- var start = + new Date();
- // Create the chart
- $('#container').highcharts('StockChart', {
- chart: {
- events: {
- load: function(chart) {
- this.setTitle(null, {
- text: 'Built chart at '+ (new Date() - start) +'ms'
- });
- }
- },
- zoomType: 'x'
- },
- rangeSelector: {
- buttons: [{
- type: 'day',
- count: 1,
- text: '24h'
- }, {
- type: 'week',
- count: 1,
- text: '1w'
- }, {
- type: 'month',
- count: 1,
- text: '1m'
- }, {
- type: 'month',
- count: 6,
- text: '6m'
- }, {
- type: 'year',
- count: 1,
- text: '1y'
- }, {
- type: 'all',
- text: 'All'
- }],
- selected: 1
- },
- xAxis: {
- ordinal: false
- },
- yAxis: {
- title: {
- text: 'Luftdruck Innen'
- }
- },
- title: {
- text: 'Luftdruck Innen'
- },
- subtitle: {
- text: 'Built chart at...' // dummy text to reserve space for dynamic subtitle
- },
- series: [{
- name: 'mB',
- type: 'line',
- data: data,
- tooltip: {
- valueDecimals: 1,
- valueSuffix: ' mB'
- },
- fillColor : {
- linearGradient : {
- x1: 0,
- y1: 0,
- x2: 0,
- y2: 1
- },
- stops : [[0, Highcharts.getOptions().colors[0]], [1, 'rgba(0,0,0,0)']]
- },
- }]
- });
- });
- });
- </script>
- </head>
- <body>
- <script src="/Highstock/code/highstock.js"></script>
- <script src="/Highstock/code/modules/exporting.js"></script>
- <div id="container" style="height: 500px; min-width: 500px"></div>
- </body>
- </html>
P_INNEN_data.php:
PHP
- <?php
- $x=$_GET["x"];
- date_default_timezone_set('Europe/Berlin');
- $con = mysql_connect("IP-Adresse der Datenbank","Benutzername","Passwort");
- if (!$con) {
- die('Could not connect: ' . mysql_error());
- }
- mysql_select_db('MyHome', $con);
- $result = mysql_query("SELECT * FROM `Messwerte` WHERE SensorID = '$x' ");
- while($row = mysql_fetch_array($result)) {
- $datum = $row['DateTime'];
- $value = round($row['Messwert'],2);
- $uts = strtotime ($datum);
- if (date('I', time()))
- {
- $uts = $uts + 7200;
- $x=1;
- }
- else
- {
- $uts=$uts+3600;
- if($x==1)
- {
- $uts=$uts-7200;
- $x=0;
- }
- }
- $datum=date('l, F j y H:i:s',$uts);
- $uts *= 1000; // convert from Unix timestamp to JavaScript time
- $data[] = array((float)$uts,(float) $value);
- }
- echo json_encode($data); //Hier wird die Tabelle an das P_INNEN.php-File zur Darstellung des Diagramms übergeben.
- mysql_close($con);
- ?>