...

View Full Version : Javascript to make graphs for elections - not working either



worldtraveller
11-15-2010, 03:32 AM
Hello here is another one i need suggestions on

here is my coding so far

<html>
<head>
<!--
New Perspectives on JavaScript
Tutorial 3
Case Problem 2

Congressional Election Results
Author:
Date: November 14 2010

Filename: election.htm
Supporting files: back.jpg, logo.jpg, results.css, votes.js

-->
<title>Congressional Races</title>
<link href="results.css" rel="stylesheet" type="text/css" />
script type="text/javascript" src="votes.js"></script>

<script type="text/javascript"> // script element to add the votes.js

function totalVotes(votes){ // script element that will calculate the array
var total = 0;
for (var i = 0; i < votes.length; i++);
{
total = total + votes[i];
}
return total;
}

function calcPercent(item,sum){ // script element to calculate the percentage which is rounded to the nearest integer
var item = Math.round((item/sum))*100); // script element to get the percentage
return item;
}
calcPercent();

function createBar(partyType,percent){ // script element to create blank cells
switch(partyType) {
case D: <td class='dem'></td>
break;
case R: <td class='rep'></td>
break;
case I: <td class='ind'></td>
break;
case G: <td class='green'></td>
break;
case L: <td class='lib'></td>
break;
}
var barTxt = partyType;

for (i=0; i < percent; i++){
document.write(barText);
}

}
function showResults(race,name,party,votes){ // script element to display the results of a particular race
var totalIV = totalVotes(votes);
document.write("<h2>race</h2>");
document.write("<table cellspacing='0'>");
document.write("<tr>");
document.write("<th>Candidate</th>");
document.write("<th class ='num'>Votes</th>");
document.write("<th class='num'>%</th>");
document.write("</tr>");

for (var i=0; i < name.length; i++){
document.write("<tr>");
document.write("<td>name(party</td>");
document.write("td class='num'>"votes</td>");

var percent=calcPercent(votes[i], totalV)

document.write("<td class='num'>(" + percent +"%)</td>");

createBar(party[i],percent)
document.write("</tr>");
}
document.write("</table>");
}
</script>

</head>

<body>

<div id="intro">
<p><img src="logo.jpg" alt="Election Day Results" /></p>
<a href="#">Election Home Page</a>
<a href="#">President</a>
<a href="#">Senate Races</a>
<a href="#">Congressional Races</a>
<a href="#">State Senate</a>
<a href="#">State House</a>
<a href="#">Local Races</a>
<a href="#">Judicial</a>
<a href="#">Referendums</a>
</div>



<div id="results">
<h1>Congressional Races</h1>
<script type="text/javascript">
showResults(race[0],name1,party1,votes1)...
showResults(race[1],name2,party2,votes2)...
showResults(race[2],name3,party3,votes3)...
showResults(race[3],name4,party4,votes4)...
showResults(race[4],name5,party5,votes5)...
</script>

</div>

</body>
</html>

______________

What i need to do is make a bar charts of elections people on the assignment, using 2 other files on a folder
the names of the other files
are votes.js and results.css

here is the link of the actual question
it is case problem 2
if u scroll down

at

http://books.google.ca/books?id=aG_T2aD84sIC&pg=PA145&lpg=PA145&dq=writeMonthCell()&source=bl&ots=EJXyGF-tbI&sig=vbgqgua2uSaL6DWp0Rx_BYoZ0z8&hl=en&ei=9C7gTLmiAYaXnAeywLWRDw&sa=X&oi=book_result&ct=result&resnum=1&ved=0CBcQ6AEwAA#v=onepage&q=writeMonthCell()&f=false




right now i did up my coding and still nothing is working

what does seem to be wrong with my coding?

any suggestions from anyone? or hints even?
thanks

Philip M
11-15-2010, 08:27 AM
showResults(race[0],name1,party1,votes1)...

Perhaps others. Have you used your error console?

When posting here please follow the posting guidelines and wrap your code in CODE tags. This means use the octothorpe or # button on the toolbar. You can (and should) edit your previous post.


It is your responsibility to die() if necessary….. - PHP Manual

Sciliano
11-15-2010, 11:07 AM
worldtraveller:

See,
http://www.freewarefiles.com/Vertical-Bar-Chart-Creator_program_52578.html

worldtraveller
11-15-2010, 11:14 AM
I use textwrangler for my MAC computer. for doing javascript on.
is there any others text editor programs that work better? thanks



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum