Re: Sparklines... and how to add them to your webpage(s)
Posted: Fri 11 Apr 2014 11:14 am
Good to see it is sorted!
All the best for a quick full recovery!
All the best for a quick full recovery!
Support forum for Cumulus weather station software
https://cumulus.hosiene.co.uk/
Steve thanks for the suggestion it works , dumb of me to forget that tagsteve wrote:You have the same issue as Ron (nitrx) earlier in the thread - decimal commas. Using the 'RC' version of the web tag may fix that, at a guess - <#RCRecentOutsideTemp>
Not sure but you've disableHighlight true according the description : Set to true to disable the highlighting of individual values when mousing over a sparkline.jnstllng wrote:Nice piece of stuff that I managed to get working on my site https://wetter.teamstelling.de.
Unfortunately, the tooltip box shows up too small and I cannot find the issue that is causing it. See the attached picture.
Any idea how to solve this?
Code: Select all
<?php
//Info for connection to database
require("db.php");
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
// The select statement
// Change interval to hours for how long to go back
// select -- list the colums i need to pass, runs a bit quicker than select *
$sql = "select temp, hum, press, dew, heatindex, wchill, wlatest, wspeed, wgust, rfall from Realtime where `LogDateTime` > Now() - interval 24 hour";
$query=mysqli_query($conn, $sql);
$i=0;
while ($list = mysqli_fetch_assoc($query)) {
// make the variables for json_encode $varname ['db_column']
$temp[$i]=$list['temp']*1;
$hum[$i]=$list['hum']*1;
$press[$i]=$list['press']*1;
$dew[$i]=$list['dew']*1;
$heatindex[$i]=$list['heatindex']*1;
$wchill[$i]=$list['wchill']*1;
$wlatest[$i]=$list['wlatest']*1;
$wspeed[$i]=$list['wspeed']*1;
$wgust[$i]=$list['wgust']*1;
$rfall[$i]=$list['rfall']*1;
$i++;
}
Code: Select all
<script type="text/javascript">
/* <![CDATA[ */
$(function() {
/* temperature sparkline() function */
// json_encode variable name to output data for script inside php
//also change var's within script to accommodate your needs its in 4 places
var recent_outside_temp = <?php echo json_encode($temp) ?>;
$('.temperature').sparkline(recent_outside_temp, {
type: "line",
tooltipSuffix: " F",
// using php to get time stamps for chart data change strtotime to hour needed to go back
tooltipChartTitle: 'Temperatures in the period<br/><?php echo date('h:i A',(strtotime ( '-24 hour') )) ?> to <?php echo date('h:i A') ?>',
width: 370,
height: 65,
});
// Insert a second/subsequent sparkline function here
});
/* <![CDATA[ */
$(function() {
/* temperature sparkline() function */
var recent_press = <?php echo json_encode($press) ?>;
$('.press').sparkline(recent_press, {
type: "line",
tooltipSuffix: " inHg",
tooltipChartTitle: 'Barometer in the period<br/><?php echo date('h:i A',(strtotime ( '-24 hour') )) ?> to <?php echo date('h:i A') ?>',
width: 370,
height: 65,
});
// Insert a second/subsequent sparkline function here
});
/* ]]> */
</script>
Code: Select all
CHANGE
$query=mysqli_query($conn, $sql);
TO
if ($query=mysqli_query($conn, $sql)) {
ADD
mysqli_free_result($query);
}
mysqli_close($conn);
Code: Select all
<?php
include_once "/var/www/db.php";
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
// The select statement
// Change interval to hours for how long to go back
$sql = "select temp, hum, press, dew, heatindex, wchill, wlatest, wspeed, wgust, rfall from Realtime where `LogDateTime` > Now() - interval 24 hour";
// $query=mysqli_query($conn, $sql);
if ($query=mysqli_query($conn, $sql)) {
$i=0;
while ($list = mysqli_fetch_assoc($query)) {
$temp[$i]=$list['temp']*1;
$hum[$i]=$list['hum']*1;
$press[$i]=$list['press']*1;
$dew[$i]=$list['dew']*1;
$heatindex[$i]=$list['heatindex']*1;
$wchill[$i]=$list['wchill']*1;
$wlatest[$i]=$list['wlatest']*1;
$wspeed[$i]=$list['wspeed']*1;
$wgust[$i]=$list['wgust']*1;
$rfall[$i]=$list['rfall']*1;
$i++;
}
mysqli_free_result($query);
}
mysqli_close($conn);
?>