john pfeiffer
  • Home
  • Categories
  • Tags
  • Archives

javascript chart two column

<html>
<body>
<script type="text/javascript">

var total = 8000000;                        //this represents the year's target
var current = 781720 + 620161 + 372628;     //these are each month's sales
var budget = 538899 + 494491 + 612168;      //this is the budget for each month

var salesweek = 12;         //this is the current week we are on
var chartmax = 50;          //this is how large we want our chart (a scale if you will)

var currentPercent = current / total;
var budgetPercent = budget / total;

// One minus the percent achieved equals the percent still left to accomplish
// Multiplied by the chartmax so that it is a whole number of blocks on the chart
var currentBreakPoint = ((1 - currentPercent ) * chartmax);
var budgetBreakPoint = ((1 - budgetPercent ) * chartmax);




function Comma(number)
{

    number = '' + number;
    if (number.length > 3)
    {
        var mod = number.length % 3;
        var output = (mod > 0 ? (number.substring(0,mod)) : '');

        for (i=0 ; i < Math.floor(number.length / 3); i++)
        {
            if ((mod == 0) && (i == 0))
            {   output += number.substring(mod+ 3 * i, mod + 3 * i + 3);    }
            else
            {       output+= ',' + number.substring(mod + 3 * i, mod + 3 * i + 3);  }
        }
        return (output);
    }
    else{    return number;     }
}

document.write( "GOAL: Pounds" + Comma( total ) );
document.write('<table border="0"><tr>');   //formatting table for 2 columns
    document.write('<td align="center">');

        document.write('<table border="0">');   //table of % achieved
        for( i=1; i< chartmax; i++)
        {
            document.write("<tr>");

            if( i > currentBreakPoint )
            {
                document.write('<td bgcolor="#ff0000">');
            }
            else{
                document.write('<td bgcolor="#00ffff">');
            }

            document.write("</td></tr>");
        }
        document.write("</table>");

document.write('<font size="1">Sales Week ' + salesweek + ' = <b>Pounds' + Comma(current) + '</b> </font>');
    document.write("</td>");
    document.write('<td align="center">');

        document.write('<table border="0">');   //table of % achieved
        for( i=1; i< chartmax; i++)
        {
            document.write("<tr>");

            if( i > budgetBreakPoint )
            {
                document.write('<td bgcolor="#ff0000">');
            }
            else{
                document.write('<td bgcolor="#00ffff">');
            }

            document.write("</td></tr>");
        }
        document.write("</table>");
document.write('<i><font size="1">(BUDGETED = </i><b>Pounds' + Comma(budget) + '</b>)</font>');


    document.write("</td>");
document.write("</tr>");
document.write("</table>");


//document.write("<br />");
//document.write('</td></tr></table>');

</script>
</body>
</html>

  • « javascript chart 2010 06 15
  • javascript chart »

Published

May 29, 2016

Category

javascript

~242 words

Tags

  • chart 4
  • column 4
  • javascript 43
  • two 3