jauge pour batterie

Ce forum est dédié aux discussions qui concernent les graphiques réalisés avec la librairie Highcharts, Une question, un bug ?

Modérateurs : jturlier, Météo Villarzel

Avatar du membre
Météo Villarzel
Administrateur du site
Messages : 524
Enregistré le : 06 févr. 2014, 09:48
Contact :

Re: jauge pour batterie

Message par Météo Villarzel » 17 avr. 2014, 09:18

Un dernier exemple avec la partie PHP épurée :lol: et plus d'options dans la partie JS
http://www.boock.ch/meteo/graphiques_ph ... _test2.php

<?php
// appel du script de connexion
require("mysql_connect.php");
$sql="select max(tstamp) from data";
$query=mysql_query($sql);
$list=mysql_fetch_array($query);
$sql = "SELECT tstamp, outdoortemperature FROM data where tstamp ORDER BY 1 DESC LIMIT 1";
$query=mysql_query($sql);
$i=0;
while ($list = mysql_fetch_assoc($query)) {
$dtime[$i]=($list['tstamp']+3600)*1000;
$dtemp[$i]=$list['outdoortemperature']*1;

Tu dois adapter le nom de ta table data dans l'exemple, la variable tstamp pour l'heure et (outdoortemperature) pour la valeur que tu veux récupérer dans ta bd

Le code complet

Code : Tout sélectionner

<?php
// appel du script de connexion
require("mysql_connect.php");                     
$sql="select max(tstamp) from data";
$query=mysql_query($sql);                  
$list=mysql_fetch_array($query);     
$sql = "SELECT tstamp, outdoortemperature  FROM data where tstamp ORDER BY 1 DESC LIMIT 1";   
$query=mysql_query($sql);                   
$i=0;
while ($list = mysql_fetch_assoc($query)) {  
$dtime[$i]=($list['tstamp']+3600)*1000;	
$dtemp[$i]=$list['outdoortemperature']*1;					
$i++;
}	
  ?>
  
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<HEAD>
<meta http-equiv="X-UA-Compatible" content="IE=9; IE=9" >
<META NAME="LANGUAGE" CONTENT="FR">
<meta http-equiv="content-type" content="text/plain; charset=ISO-8859-1"> 
<title></title>     
      <!-- 1. Add these JavaScript inclusions in the head of your page -->
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>           
<script type="text/javascript" src="http://code.highcharts.com/highcharts.js"></script>
<script type="text/javascript" src="http://code.highcharts.com/highcharts-more.js"></script>  
<script type="text/javascript" src="http://code.highcharts.com/themes/grid.js"></script>
<script type="text/javascript" src="http://code.highcharts.com/modules/exporting.js"></script>
   
      <!-- 2. Add the JavaScript to initialize the chart on document ready -->
      <script type="text/javascript">  
    function comArr(unitsArray) { 
        var outarr = [];
        for (var i = 0; i < dTime.length; i++) {
         outarr[i] = [dTime[i], unitsArray[i]];
        }
      return outarr;
    } 
    
$(function () {
    var chart;        
         $(document).ready(function() {      
         var highchartsOptions = Highcharts.setOptions(Highcharts.theme);       
         Highcharts.setOptions({
        
      });
        chart = new Highcharts.Chart({
            chart: {
            renderTo: 'container',
           type: 'gauge',
           alignTicks: false,
           plotBackgroundColor: null,
           plotBackgroundImage: null,
           plotBorderWidth: 0,
           plotShadow: false
       },
   
       title: {
           text: 'test'
       },
		credits: {
            text: 'Météo Villarzel',
            href: '',
			position: {
			align: 'center',
			x: 0,
			verticalAlign: 'bottom',
			y: -65
			}
			},
            
      pane: {
	        startAngle: -150,
	        endAngle: 150,
	        background: [{
	            backgroundColor: {
	                linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1 },
	                stops: [
	                    [0, '#FFF'],
	                    [1, '#333']
	                ]
	            },
	            borderWidth: 0,
	            outerRadius: '109%'
	        }, {
	            backgroundColor: {
	                linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1 },
	                stops: [
	                    [0, '#333'],
	                    [1, '#FFF']
	                ]
	            },
	            borderWidth: 1,
	            outerRadius: '107%'
	        }, {
	            // default background
	        }, {
	            backgroundColor: '#DDD',
	            borderWidth: 0,
	            outerRadius: '105%',
	            innerRadius: '103%'
	        }]
	    },           
   
       yAxis: [{
           min: -40,
           max: 40,
            minorTickInterval: 'auto',
	        minorTickWidth: 1,
	        minorTickLength: 15,
	        minorTickPosition: 'inside',
	        minorTickColor: '#666',
	
	        tickPixelInterval: 30,
	        tickWidth: 2,
	        tickPosition: 'inside',
	        tickLength: 23,
	        tickColor: '#666',
	        labels: {
				distance: -40,
	            step: 2,
	            rotation: 'auto'
	        },
		   title: {
	            text: 'Température'
	        },
	        plotBands: [{
	            from: -40,
	            to: -15,
	            color: '#7adeec',
				outerRadius: '100%',
				thickness: '12%'
	        }, {
	            from: -15,
	            to: 15,
	            color: '#1f9bdc',
				outerRadius: '100%',
				thickness: '12%'
	        }, {
	            from: 15,
	            to: 40,
	            color: '#ea8870', 
				outerRadius: '100%',
				thickness: '12%'
	        },

			],
			
           offset: 0,
           endOnTick: false
       }],
	   plotOptions: {
			gauge: {
				dial: {
				// dial=aiguille
					radius: '80%',
					backgroundColor: 'black',
					borderColor: 'black',
					borderWidth: 1,
					baseWidth: 3,
					topWidth: 0,
					baseLength: '70%', // of radius
					rearLength: '20%'
				},pivot: {
				// centre aiguille
					radius: 10,
					borderWidth: 1,
					borderColor: 'gray',
					backgroundColor: {
					linearGradient: { x1: 0, y1: 0, x2: 1, y2: 1 },
					stops: [
							[0, 'white'],
							[1, 'gray']
						]
					}	
				},dataLabels: {
                    enabled: true,
                    borderRadius: 5,
                    format: '{y} °C',
                    // backgroundColor: 'rgba(252, 255, 197, 0.7)',
                    borderWidth: 1,
                    borderColor: '#AAA',
                    y: 65
                }
			}
		},
   
       series: [{
           name: 'temp',
           data: comArr(dTemp),
           
           tooltip: {
               valueSuffix: ' °C'
           }
       }]
   
   });
});
});
eval(<?php echo  "'var dTime =  ".json_encode($dtime)."'" ?>);
eval(<?php echo  "'var dTemp =  ".json_encode($dtemp)."'" ?>);

   </script>
   </head>
   <body>
      <div id="container" style="width: 900px; height: 450px; margin: 0 auto"></div>
   </body>
</html>
Station Vantage Pro2+ avec station agricole - Weatherlink - GraphWeather 3.0.15b - Cumulus 1.9.4 - Windows 7/64
Graphique dynamique à partir d'une bd MySql - VP2SQL

Image

Avatar du membre
helmain
Administrateur du site
Messages : 54
Enregistré le : 09 févr. 2014, 12:44
Localisation : FRANCE - Lagny-sur-Marne (77)
Contact :

Re: jauge pour batterie

Message par helmain » 17 avr. 2014, 12:54

Pour ta requête Pierre-André, on peut faire plus simple en y mettant une sous requête.
Du moment qu'on ne recherche pas des valeurs sur une plage de temps.
Et pas besoin du timestamp puisqu'il n'est pas affiché sur le graphique.

Code : Tout sélectionner

"SELECT outdoortemperature FROM data where tstamp = (select max(tstamp) from data)";
Ca n'a rien de compliqué quand on sait comment faire. :lol:
Station Vantage Pro2 + Soil/Leaf + Anémomètre déporté - Weatherlink 6.0.3 - Weather Display 10.37S build 84 - Cumulus 1.9.4 build 1099 - GraphWeather 3.0.28 - Windows 10/64 - VP2SQL + WDTU 1.2 pour Envoy8x - Hébergé par o2switch (MySql/PgSql)

Image

nicoyo55
Messages : 4
Enregistré le : 15 avr. 2014, 16:12

Re: jauge pour batterie

Message par nicoyo55 » 17 avr. 2014, 13:55

merci pour vos reponses je pense que je vais arriver a me debrouiller avec tout ca :D merci encore

nicoyo55
Messages : 4
Enregistré le : 15 avr. 2014, 16:12

Re: jauge pour batterie

Message par nicoyo55 » 17 avr. 2014, 14:49

c'est bon ca marche niquel merci beaucoup pour votre aide mais je ne comprends toujours pas pourquoi rien ne s'afficher avant :)

Avatar du membre
Météo Villarzel
Administrateur du site
Messages : 524
Enregistré le : 06 févr. 2014, 09:48
Contact :

Re: jauge pour batterie

Message par Météo Villarzel » 17 avr. 2014, 15:39

Bon tant mieux, mais c'est vrai qu'une simple virgule qui manque dans la partie JS et plus rien ne s'affiche.

A+
Station Vantage Pro2+ avec station agricole - Weatherlink - GraphWeather 3.0.15b - Cumulus 1.9.4 - Windows 7/64
Graphique dynamique à partir d'une bd MySql - VP2SQL

Image

Avatar du membre
helmain
Administrateur du site
Messages : 54
Enregistré le : 09 févr. 2014, 12:44
Localisation : FRANCE - Lagny-sur-Marne (77)
Contact :

Re: jauge pour batterie

Message par helmain » 17 avr. 2014, 16:16

Salut nicoyo55,
Pour avoir rien de chez rien en affichage, ça peut aussi être le chemin des bibliothèques highcharts et/ou jquery qui n'était pas exact.
Si un jour un problème identique se produit, ouvre le fichier source et cherche ce qui ne va pas.
Si le fait de cliquer sur un lien d'une bibliothèque te renvoie sur un "Not Found" ou une erreur 404, alors c'est ton chemin (généralement relatif) qui est KO
Si c'est tout blanc, alors c'est une virgule, ou une parenthèse, crochet ou accolade qui est orphelin.
Enfin, je suis bien content que maintenant tout fonctionne. :D

Jean-Michel
Station Vantage Pro2 + Soil/Leaf + Anémomètre déporté - Weatherlink 6.0.3 - Weather Display 10.37S build 84 - Cumulus 1.9.4 build 1099 - GraphWeather 3.0.28 - Windows 10/64 - VP2SQL + WDTU 1.2 pour Envoy8x - Hébergé par o2switch (MySql/PgSql)

Image

Répondre