Welcome to the Cumulus Support forum.

Latest Cumulus MX V3 release 3.28.6 (build 3283) - 21 March 2024

Cumulus MX V4 beta test release 4.0.0 (build 4018) - 28 March 2024

Legacy Cumulus 1 release v1.9.4 (build 1099) - 28 November 2014 (a patch is available for 1.9.4 build 1099 that extends the date range of drop-down menus to 2030)

Download the Software (Cumulus MX / Cumulus 1 and other related items) from the Wiki

Trend arrow Javascript

Other discussion about creating web sites for Cumulus that doesn't have a specific subforum

Moderator: daj

Areco747
Posts: 102
Joined: Sun 05 Oct 2008 2:13 pm
Weather Station: WH-1081
Operating System: Windows XP
Location: San Antonio de Areco-Buenos Aires - Argentina
Contact:

Trend arrow Javascript

Post by Areco747 »

Hi !! I need help with this JavaScript indicating the temperature trend arrow (Up or down)

<td><#temp>&nbsp;<#tempunit><script type="text/javascript">
var temp = "<#temptrend>";
if (temp=="0"){var imagen = "steady.bmp";}
if (temp>"0"){var imagen = "up.bmp";}
if (temp<"0"){var imagen = "down.bmp";}
document.write('<img src="http://arecoclima.com.ar/xxxxx/'+imagen+'"/>');
</script></td>

When trend is 0: is correct arrow steady and similar when trend is negative.(arrow down)
But when the trend is positive (example +1.2) continuous with the down arrow. Where I have the error?

Many thanks,

Mauricio
Mauricio
----------------------------------------------------------------------------------------

Image


http://www.arecoclima.com.ar
User avatar
steve
Cumulus Author
Posts: 26702
Joined: Mon 02 Jun 2008 6:49 pm
Weather Station: None
Operating System: None
Location: Vienne, France
Contact:

Re: Trend arrow Javascript

Post by steve »

I think the problem is that you are comparing strings, not numbers. I think you need:

Code: Select all

var temp = <#temptrend>;
if (temp==0){var imagen = "steady.bmp";}
if (temp>0){var imagen = "up.bmp";}
if (temp<0){var imagen = "down.bmp";}
Steve
Areco747
Posts: 102
Joined: Sun 05 Oct 2008 2:13 pm
Weather Station: WH-1081
Operating System: Windows XP
Location: San Antonio de Areco-Buenos Aires - Argentina
Contact:

Re: Trend arrow Javascript

Post by Areco747 »

Steve if I remove the quotes 0 instead of "0" continues the problem.
You do not have the required permissions to view the files attached to this post.
Mauricio
----------------------------------------------------------------------------------------

Image


http://www.arecoclima.com.ar
User avatar
steve
Cumulus Author
Posts: 26702
Joined: Mon 02 Jun 2008 6:49 pm
Weather Station: None
Operating System: None
Location: Vienne, France
Contact:

Re: Trend arrow Javascript

Post by steve »

Can you show me the page where you have this code?

I took a copy of your current page at http://arecoclima.com.ar/, which had this code in it:

Code: Select all

var temp = "+1.3"; 
if (temp=="0"){var imagen = "steady.bmp";}
if (temp<"0"){var imagen = "up.bmp";}
if (temp>"0"){var imagen = "down.bmp";}
I edited the code to this:

Code: Select all

var temp = 0; 
if (temp==0){var imagen = "steady.bmp";}
if (temp>0){var imagen = "up.bmp";}
if (temp<0){var imagen = "down.bmp";}
And I got this:
temp1.png
I edited it to this:

Code: Select all

var temp = +1.3; 
if (temp==0){var imagen = "steady.bmp";}
if (temp>0){var imagen = "up.bmp";}
if (temp<0){var imagen = "down.bmp";}
And I got this:
temp2.png
I edited it to this:

Code: Select all

var temp = -1.3; 
if (temp==0){var imagen = "steady.bmp";}
if (temp>0){var imagen = "up.bmp";}
if (temp<0){var imagen = "down.bmp";}
And I got this:
temp3.png
You do not have the required permissions to view the files attached to this post.
Steve
Areco747
Posts: 102
Joined: Sun 05 Oct 2008 2:13 pm
Weather Station: WH-1081
Operating System: Windows XP
Location: San Antonio de Areco-Buenos Aires - Argentina
Contact:

Re: Trend arrow Javascript

Post by Areco747 »

Steve: The page is http://www.arecoclima.com.ar/index.htm and the current code is:

var temp = "<#temptrend>";
if (temp=="0"){var imagen = "steady.bmp";}
if (temp<"0"){var imagen = "up.bmp";}
if (temp>"0"){var imagen = "down.bmp";}


But in this case by lowering the trend continues up arrow.

Now I change if (temp > "0") for if (temp<" 0 ") so that the arrow goes up, but this sunset when the negative trend is continue the arrow up and I have to modify the code again.

Thanks.
Mauricio
----------------------------------------------------------------------------------------

Image


http://www.arecoclima.com.ar
User avatar
steve
Cumulus Author
Posts: 26702
Joined: Mon 02 Jun 2008 6:49 pm
Weather Station: None
Operating System: None
Location: Vienne, France
Contact:

Re: Trend arrow Javascript

Post by steve »

I don't understand; you said you had removed the quotes as I suggested, but they are still there. The code you need, which I have tested in all three situations, is in my first reply.
Steve
Areco747
Posts: 102
Joined: Sun 05 Oct 2008 2:13 pm
Weather Station: WH-1081
Operating System: Windows XP
Location: San Antonio de Areco-Buenos Aires - Argentina
Contact:

Re: Trend arrow Javascript

Post by Areco747 »

Steve: Now add your code without quotes and without quotes in <#temptrend>.

var temp = <#temptrend>;
if (temp==0){var imagen = "steady.bmp";}
if (temp>0){var imagen = "up.bmp";}
if (temp<0){var imagen = "down.bmp";}

And update to the site Ok.

I'll try it this afternoon with the temperature down if it responds.

Thank for you help !!! :)
Mauricio
----------------------------------------------------------------------------------------

Image


http://www.arecoclima.com.ar
Areco747
Posts: 102
Joined: Sun 05 Oct 2008 2:13 pm
Weather Station: WH-1081
Operating System: Windows XP
Location: San Antonio de Areco-Buenos Aires - Argentina
Contact:

Re: Trend arrow Javascript

Post by Areco747 »

Steve, now with trend steady and down, update Ok.

Many Thanks!!
You do not have the required permissions to view the files attached to this post.
Mauricio
----------------------------------------------------------------------------------------

Image


http://www.arecoclima.com.ar
User avatar
steve
Cumulus Author
Posts: 26702
Joined: Mon 02 Jun 2008 6:49 pm
Weather Station: None
Operating System: None
Location: Vienne, France
Contact:

Re: Trend arrow Javascript

Post by steve »

Muy bueno! :)
Steve
Palmyweather
Posts: 52
Joined: Sat 28 Nov 2009 9:57 am
Weather Station: W1081
Operating System: Windows 7
Location: New Zealand
Contact:

Re: Trend arrow Javascript

Post by Palmyweather »

I did my trends something like this:

E.G. Wind:

Code: Select all

 <script type="text/javascript">
		var windaverage = *VALUE*;
		var windlatest = *VALUE*;
		if (windlatest>windaverage)
		document.write('<img src="dbimages/risingarrow.gif"  width="7px" height="7px"  align="absmiddle" border="0" alt="Current trend is " title="Current trend is rising" />'); 
		else if (windlatest<windaverage)
		document.write('<img src="dbimages/fallingarrow.gif"  width="7px" height="7px"  align="absmiddle" border="0" alt="Current trend is " title="Current trend is falling" />'); 
		else
		document.write('<img src="dbimages/steadyarrow.gif"  width="7px" height="7px"  align="absmiddle" border="0" alt="Current trend is " title="Current trend is steady" />'); 
</script>
And for those that are calculated by Cumulus software, something very simple like this:

Code: Select all

<img src="dbimages/<#temptrendenglish>arrow.gif"  width="7px" height="7px"  align="baseline" border="0" alt="Current trend is <#temptrendtext>" title="Current trend is <#temptrendtext>" />
So of course I named my arrows "Rising" "Falling" and "Steady". Works well for me. Will soon be introducing wind direction arrows based upon the latter principal.

Someone will probably find holes in what I have done but seems okay to me.
Check my Palmerston North, New Zealand weather station out at https://palmyweather.co.nz .

Image
User avatar
GraemeT
Posts: 312
Joined: Wed 21 Oct 2009 11:19 am
Weather Station: La Crosse WS-2355 & WS-2306
Operating System: Windoze 7, 10, 11
Location: Bayswater, Australia
Contact:

Re: Trend arrow Javascript

Post by GraemeT »

I just thought I'd muscle in with my bit, too.
Not much good with javascript, so here's the php code I use:

Code: Select all

....html

	      <?php if ($temptrendenglish == 'Rising') echo '<img src="images/trendup.png" alt="" />';
		  else if ($temptrendenglish == 'Falling') echo '<img src="images/trenddn.png" alt="" />';
		  else echo '<img src="images/steady.png" alt="" />'; ?>

more html...
The same structure is used to show pressure trend.

...I wonder how many different ways there are of achieving a result...
Cheers,
Graeme.
Areco747
Posts: 102
Joined: Sun 05 Oct 2008 2:13 pm
Weather Station: WH-1081
Operating System: Windows XP
Location: San Antonio de Areco-Buenos Aires - Argentina
Contact:

Re: Trend arrow Javascript

Post by Areco747 »

This is my final work, thank you all!! www.arecoclima.com.ar
Mauricio
----------------------------------------------------------------------------------------

Image


http://www.arecoclima.com.ar
corsair
Posts: 5
Joined: Tue 09 Nov 2010 10:38 am
Weather Station: Davis Vantage Pro 2
Operating System: Win Seven

Re: Trend arrow Javascript

Post by corsair »

Impossible to manage it... I try everything (I think...) Can you ,please, tell me what am I doing wrong??? :bash: :bash:
Here is my page... http://www.corsair.gr/wxpage/lc3600.html
User avatar
steve
Cumulus Author
Posts: 26702
Joined: Mon 02 Jun 2008 6:49 pm
Weather Station: None
Operating System: None
Location: Vienne, France
Contact:

Re: Trend arrow Javascript

Post by steve »

corsair wrote:Impossible to manage it... I try everything (I think...) Can you ,please, tell me what am I doing wrong???
It's the 'comma' decimal separator which Javascript doesn't understand. You can use the web tags which replace the comma with a decimal point, which are there for this purpose. There may be ways of getting Javascript to understand the commas; I don't know.
Steve
User avatar
mcrossley
Posts: 12695
Joined: Thu 07 Jan 2010 9:44 pm
Weather Station: Davis VP2/WLL
Operating System: Bullseye Lite rPi
Location: Wilmslow, Cheshire, UK
Contact:

Re: Trend arrow Javascript

Post by mcrossley »

Post Reply