Barchart Routine

Feb 23, 2004

Nowhere as complex as some of the scripts posted in this section, but just a little one I wrote. You just use three lines to create and render the barchart:

<html>
<head>
<title>Bar Charts</title>
<style>
.barchart {
table-layout:fixed;
font:normal normal normal small normal monospace;
}

.bar {
position:relative;
margin-bottom:0px;
width:45px;
background-color:#999999;
}
</style>

<script>
function Barchart(id) {
var entries=new Array();
var maxHeight=0;
var absoluteMax=300;

this.setEntries=function() {
for (i=0;i<arguments.length;i+=2) {
entries[i/2]=new Array();
entries[i/2][0]=arguments[i];
if (!isNaN(arguments[i+1])) {
entries[i/2][1]=arguments[i+1];// COULD USE toPrecision() for newer
maxHeight=(entries[i/2][1]>maxHeight)?entries[i/2][1]:maxHeight;
} else {
throw "Value of parameter "+(i+1)*1+" is not a number";
}
}
};

this.toString=function() {
var str="<table id='"+id+"' class='barchart' cellpadding=&#393;' cellspacing=&#390;' border=&#390;'>"+
"<tr valign='bottom' align='center'>";
for (i=0;i<entries.length;i++) {
var h=parseInt((entries[i][1]/maxHeight)*absoluteMax)
str+="<td width=&#3950;' valign='bottom' align='center'>"+entries[i][1]+
"<div class='bar' style='height:"+h+";background-color:"+Barchart.colors[i%Barchart.colors.length]+"'></div></td>";
}
str+="</tr><tr align='center'>";
for (i=0;i<entries.length;i++) {
str+="<td width=&#3950;' align='center'>"+entries[i][0]+"</td>";
}
str+="</tr></table>";
return str;
};
}
Barchart.colors=new Array();
Barchart.colors[0]="blue";
Barchart.colors[1]="green";
Barchart.colors[2]="purple";
Barchart.colors[3]="brown";

</script>
</head>

<body>
Test Page for Bar Charts<br><br>
<script>
// THE CALL TO CREATE AND RENDER THE BARCHART IS BELOW - 3 LINES
var b=new Barchart();
b.setEntries("Anton", 30, "Angela", 55, "Cecile", 24, "Leon", 64, "Rosie", 18);
document.write(b);
</script>
</body>
</html>

View 1 Replies


ADVERTISEMENT

Execute A Vbscript Sub Routine?

May 8, 2010

From inside a javascript function i need to execute a vbscript sub routine.
You might be thinking why i can't do it in javascript. well i probably can but i am better at VBscript and it would be a lot easier.

View 3 Replies View Related

Calling MySQL Routine ?

Mar 23, 2011

I am creating a simple Web App using Helios (Eclipse).

It needs to do two things :

1) Accept an integer via a text box from the user

2) Call a mySQL routine (stored proc), via a button, and pass the integer from step 1 to this stored procedure. Return results to page.

How would I do this (mainly step 2) using JavaScript, or am I barking up the wrong tree?

View 1 Replies View Related

JQuery :: Cannot Add SELECT Option From Inside GetJSON Routine

May 9, 2011

I ve got a bit of a problem adding new options to select. It works fine out of the getJSON routine (see commented line) PHP data supplier returns proper values and alert displays them fine, but can not add them to select

Using Multiselect widget from - http://www.erichynds.com/jquery/jquery-ui-multiselect-widget/
and jQuery 1.6 + UI 1.82

[URL]

$("#1").bind("multiselectclose", function(event, ui){
var checked1 = $("#1").multiselect("getChecked").map(function(){return this.value;}).get();
if (checked1<1){

[Code]....

View 1 Replies View Related

Routine To Remove Extra Newline Chars And Carriage Return

May 30, 2007

I there a quick routine that removes trailing newline chars and carriage return?

View 5 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved