Page 1 of 1
Adding a 24 hour trend to current conditions
Posted: Fri 11 Dec 2020 5:49 pm
by inmyrvm
I searched around the forum and didn't see this posted but I suspect it's not difficult. I'd like to add a 24 hour trend to my current conditions. For example, on the "Now" page have the current temperature and then next to it have a plus or minus trend from 24 hours ago to show whether it's warmer or cooler than yesterday. Obviously the data is available to do this and there is the trends page with very nice graphics, but I like the trend number next to the current value for quick reference. Has anyone done this on their own? When I used Virtual Weather Station years ago it had specific tags for conditions 24 hours ago so it was just a matter of adding that tag to the web page. I suspect it would be a similar process in MX but I'm just not familiar enough with how to do that.
Thanks.
Update: Just noticed a similar thread in the CumulusMX current section of the message board (
viewtopic.php?f=40&t=18669) but no definitive solutions yet. Maybe not as simple as I assumed. Hoping someone might have some ideas. Apologies if this wasn't quite the right board section for this topic. I'm still very new to this.
Re: Adding a 24 hour trend to current conditions
Posted: Sat 12 Dec 2020 3:44 pm
by mcrossley
You would have to add a little bit of JavaScript to the page to subtract the two values and display the the result.
Something like- untested - (where "id_name" is the id you allocate to the span or whatever to contain the text)
Code: Select all
let diff = <#temp> - <#RecentOutsideTemp h=24>;
if (diff > 0) {
diff = '+' + diff;
}
$('#id_name').text(diff);
Re: Adding a 24 hour trend to current conditions
Posted: Sat 12 Dec 2020 5:27 pm
by beteljuice
Just noticed a similar thread in the CumulusMX current section of the message board (viewtopic.php?f=40&t=18669) but no definitive solutions yet.
The suggestions offered half way down the first page are valid provided that your page is
Template driven.
The problem for that gentleman (when we eventually found out) was that he wanted to create a data file (on his PC) to upload for use by a third-party.
Re: Adding a 24 hour trend to current conditions
Posted: Sun 13 Dec 2020 6:31 am
by inmyrvm
Thank you for those! I liked the addition of the code include a "+" to make it obvious it's a trend, but I must be missing something in the syntax because it's not writing the output to the page. I looked up javascript examples and tried a few things but nothing was working. Also I wasn't sure what the purpose was of #id_name. Is that how the output gets written to the page? Here's what I tried (just added the document.write at the end):
<script>let diff = <#temp> - <#RecentOutsideTemp d=1>;
if (diff > 0) {
diff = '+' + diff;
}
$('#id_name').text(diff);
document.write(diff);
</script>
With the other response referencing the example from an earlier thread I was able to make that work using this code:
<script>document.write((<#RCtemp>*10 - <#RCRecentOutsideTemp d=1>*10) / 10);</script>
The original code without the extra math gave me a long decimal but this truncated it to one decimal. But that code didn't have the + symbol for positive trends which I really like and can't seem to get in there.
Thanks,
Mike
Re: Adding a 24 hour trend to current conditions
Posted: Sun 13 Dec 2020 8:11 am
by beteljuice
$('#id_name').text(diff); Is
JQuery, the plain old javascript version would be ...
Code: Select all
document.getElementById("a_name").innerHTML = diff;
and the html ..
Delta T24 <span id="a_name">?</span>
but you can just
Delta T24 <script>document.write(diff)</script>
Where ? is replaced by the value of diff
NOTE: if using $("#id_name") or document.getElementById( .... the actual script code needs to be at the bottom of your page (somewhere below <element id= ...)
Whereas ...
With the other code, break it down a bit ...
Code: Select all
<script>
diff = (<#RCtemp>*10 - <#RCRecentOutsideTemp d=1>*10) / 10;
if (diff > 0) {
diff = '+' + diff;
}
</script>
If using document.write( ... the script code needs to be ABOVE the document.write
Fun isn't it

Re: Adding a 24 hour trend to current conditions
Posted: Sun 13 Dec 2020 5:21 pm
by inmyrvm
That worked out perfectly. Thanks for the help.
Mike