Welcome to the new home of the Cumulus Support forum.

Latest Cumulus release v1.9.4 (build 1099) - Nov 28 2014
Latest Cumulus MX release - v3.0.0 build 3044 7 December 2018. See the Wiki for download

Trend arrow Javascript

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

Moderator: daj

User avatar
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 » Sat 31 Jul 2010 2:26 pm

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: 26714
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 » Sat 31 Jul 2010 3:08 pm

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

User avatar
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 » Sat 31 Jul 2010 3:19 pm

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: 26714
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 » Sat 31 Jul 2010 3:42 pm

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

User avatar
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 » Sat 31 Jul 2010 4:06 pm

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: 26714
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 » Sat 31 Jul 2010 4:14 pm

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

User avatar
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 » Sat 31 Jul 2010 4:48 pm

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

User avatar
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 » Sat 31 Jul 2010 8:44 pm

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: 26714
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 » Sat 31 Jul 2010 11:34 pm

Muy bueno! :)
Steve

Palmyweather
Posts: 38
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 » Sat 07 Aug 2010 9:44 am

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 Weather Station out at http://palmyweather.co.nz .

Image

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

Re: Trend arrow Javascript

Post by GraemeT » Sat 07 Aug 2010 2:52 pm

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.

Image

User avatar
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 » Sun 08 Aug 2010 6:07 pm

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 » Mon 15 Nov 2010 8:41 am

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: 26714
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 » Mon 15 Nov 2010 8:46 am

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: 5234
Joined: Thu 07 Jan 2010 9:44 pm
Weather Station: Davis VP2
Operating System: Stretch Lite rPi
Location: Wilmslow, Cheshire, UK
Contact:

Re: Trend arrow Javascript

Post by mcrossley » Mon 15 Nov 2010 8:47 am


Post Reply