Active TopicsActive Topics  Display List of Forum MembersMemberlist  Search The ForumSearch  HelpHelp
  RegisterRegister  LoginLogin
PowerHome Macros, Scripts, and Formulas Repository
 PowerHome Messageboard : PowerHome Macros, Scripts, and Formulas Repository
Subject Topic: Javascript Bargraphs to display temps etc Post ReplyPost New Topic
Author
Message << Prev Topic | Next Topic >>
krommetje
Super User
Super User
Avatar

Joined: December 29 2004
Location: Netherlands
Online Status: Offline
Posts: 695
Posted: December 19 2007 at 05:02 | IP Logged Quote krommetje

This piece of code draws bargraphs on the screen to display numeric values, in my case, temperatures.

Code:


<html>
<head>
<!--
This file retrieved from the JS-Examples archives
http://www.js-examples.com
1000s of free ready to use scripts, tutorials, forums.
Author: dickmann.org - http://www.dickmann.org/
-->


</head>
<body>

<script>
border=2
width=25
n_bars=3
function bar(high,val){
document.write("<td valign=bottom>",high,
   "<table bgcolor=#aa2222 border=",border," height=",high,
   " width=",width,
   " cellpadding=0 cellspacing=0>",
   "<tr><td align=center valign=bottom>",
   "<font color=#00000 size=-1 >",val,"</font>",
    "</td></tr></table> ;</ td>")
}



document.writeln("<table bgcolor=#a0a0a0 height=200 width=",
n_bars*width," border=",border," >");
//make Netscape 2.0 happy, without surrounding table, the bars are verticaly tiled
//and without a border there is only text shown
bar(<%case (len (mid("{SENSOR2}",1 ,4)) when 3 then {SENSOR2}/10 when 2 then {SENSOR2} when 1 then {SENSOR2} else {SENSOR2}/100) %>,1);
bar(<% case (len (mid("{SENSOR3}",1 ,4)) when 3 then {SENSOR3}/10 when 2 then {SENSOR3} when 1 then {SENSOR3} else {SENSOR3}/100) %>,2);
bar(<% case (len (mid("{SENSOR0}",1 ,4)) when 3 then {SENSOR0}/10 when 2 then {SENSOR0} when 1 then {SENSOR0} else {SENSOR0}/100) %>,3);
bar(<% case (len (mid("{SENSOR1}",1 ,4)) when 3 then {SENSOR1}/10 when 2 then {SENSOR1} when 1 then {SENSOR1} else {SENSOR1}/100) %>,4);
document.writeln("</table>");
</script>
</body>
</html>



Some explanation:
Code:

border=2
width=25
n_bars=3

controls The Bordertype, the width and how many bars are displayed.

Code:

bar(<%case (len (mid("{SENSOR2}",1 ,4)) when 3 then {SENSOR2}/10 when 2 then {SENSOR2} when 1 then {SENSOR2} else {SENSOR2}/100) %>,1);
bar(<% case (len (mid("{SENSOR3}",1 ,4)) when 3 then {SENSOR3}/10 when 2 then {SENSOR3} when 1 then {SENSOR3} else {SENSOR3}/100) %>,2);
bar(<% case (len (mid("{SENSOR0}",1 ,4)) when 3 then {SENSOR0}/10 when 2 then {SENSOR0} when 1 then {SENSOR0} else {SENSOR0}/100) %>,3);
bar(<% case (len (mid("{SENSOR1}",1 ,4)) when 3 then {SENSOR1}/10 when 2 then {SENSOR1} when 1 then {SENSOR1} else {SENSOR1}/100) %>,4);


this is an example of displaying temperatures but you can substitute your own code as long as is between the <% and %> and it is a numeric value... any other type will not display anything. I leave it to your fantasy in how to implement it in your HA-screens.

Peter

Edited by krommetje - December 19 2007 at 05:03
Back to Top View krommetje's Profile Search for other posts by krommetje Visit krommetje's Homepage
 
hotcoffee76
Newbie
Newbie


Joined: December 04 2009
Location: Canada
Online Status: Offline
Posts: 12
Posted: December 04 2009 at 23:48 | IP Logged Quote hotcoffee76

Hi,

What did you use for the temperature sensors?

Thanks.
Back to Top View hotcoffee76's Profile Search for other posts by hotcoffee76
 
krommetje
Super User
Super User
Avatar

Joined: December 29 2004
Location: Netherlands
Online Status: Offline
Posts: 695
Posted: December 05 2009 at 08:40 | IP Logged Quote krommetje

See all the info here on the follwing thread on this board:

http://www.power-home.com/forum/forum_posts.asp?TID=406

Peter
Back to Top View krommetje's Profile Search for other posts by krommetje Visit krommetje's Homepage
 

If you wish to post a reply to this topic you must first login
If you are not already registered you must first register

  Post ReplyPost New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum