Free Script And Source
Code For Webmaster ,ASP,HTML,VB,Java, Java Script, Dhtml,xml,ajax,programming: Calculators: Function Grapher (Function Page)
Simply click inside the window below, use your cursor to highlight the script, and copy (type Control-c or Apple-c) the script into a new file in your text editor (such as Note Pad or Simple Text) and save (Control-s or Apple-s). The script is yours!!!
Free Script And Source Code For Webmaster ,ASP,HTML,VB,Java, Java Script, Dhtml,xml,ajax,programming: Calculators: Function Grapher (Draw Graph Page)
Simply click inside the window below, use your cursor to highlight the script, and copy (type Control-c or Apple-c) the script into a new file in your text editor (such as Note Pad or Simple Text) and save (Control-s or Apple-s). The script is yours!!!
<!-- TWO STEPS TO INSTALL FUNCTION GRAPHER:
1. Paste this HTML code into a new file, name it drawGraph.html
2. Save the necessary images to your web site directory -->
<!-- STEP ONE: Paste this file into a new page, call it drawGraph.html -->
<html>
<head>
</head>
<style>
.point
{
position: absolute;
}
</style>
<script>
function getParams()
{
var idx = document.URL.indexOf('?');
var params = new Array();
if (idx != -1)
{
var pairs = document.URL.substring(idx+1, document.URL.length).split('&');
for (var i=0; i<pairs.length; i++)
{
nameVal = pairs[i].split('=');
params[nameVal[0]] = nameVal[1];
}
}
return params;
}
dotCode = '<div class="point" id="pdot_id"><img src="graph.gif" width="1" height="pic_height" alt="pic_alt"></div>\n';
xCode = '<div class="point" id="xAxis"><table border="0" width="x_width" cellspacing="0" cellpadding="0"><tr><td width="100%" bgcolor="#000000"><img src="espace.gif" width="1" height="1"></td></tr></table></div>\n';
yCode = '<div class="point" id="yAxis"><table border="0" height="y_height" cellspacing="0" cellpadding="0"><tr><td width="100%" bgcolor="#000000"><img src="espace.gif" width="1" height="1"></td></tr></table></div>\n';
backCode = '<div class="point" id="background"><table border="0" height="back_height" width="back_width" cellspacing="0" cellpadding="0"><tr><td width="100%" bgcolor="#EEEEEE"> </td></tr></table></div>\n';
if (navigator.appName == 'Netscape')
{
leftCode = 'document.obj_id.left = ';
topCode = 'document.obj_id.top = ';
}
else
{
leftCode = 'document.all.obj_id.style.left = ';
topCode = 'document.all.obj_id.style.top = ';
}
params = getParams();
fct = unescape(params["graph"]);
xMin = parseFloat(params["minX"]); xMax = parseFloat(params["maxX"]);
nbXs =200; nbYs = 200;
maxYpos = 225; minXpos = 25;
x = xMin;
yZero = Math.abs(eval(fct));
yMax = yZero;
yMin = yZero;
datas = new Array();
deltaX = (xMax - xMin) / nbXs;
i = 0;
while (x <= xMax)
{
y = eval(fct);
datas[i] = x + ':' + y;
yMax = Math.max(y, yMax);
yMin = Math.min(y, yMin);
yZero = Math.min(yZero, Math.abs(y))
x+= deltaX; i++;
}
deltaY = nbYs / (yMax - yMin);
yPos = new Array();
for (i=0; i<datas.length; i++)
{
yPos[i] = maxYpos - (((datas[i].split(':'))[1] - yMin) * deltaY);
}
document.write(backCode.replace(/back_width/, nbXs).replace(/back_height/, nbYs));
eval(leftCode.replace(/obj_id/, 'background') + minXpos);
eval(topCode.replace(/obj_id/, 'background') + (maxYpos - nbYs));
if ((xMin * xMax) < 0)
{
document.write(yCode.replace(/y_height/, nbXs));
eval(leftCode.replace(/obj_id/, 'yAxis') + (minXpos - (xMin * (nbXs/(xMax - xMin)))));
eval(topCode.replace(/obj_id/, 'yAxis') + (maxYpos - nbYs));
}
if ((yMin * yMax) <= 0)
{
document.write(xCode.replace(/x_width/, nbYs));
eval(leftCode.replace(/obj_id/, 'xAxis') + minXpos);
eval(topCode.replace(/obj_id/, 'xAxis') + (maxYpos - ((yZero - yMin) * deltaY)));
}
for (i=1; i<(datas.length-1); i++)
{
picHeight = Math.abs((yPos[i-1] - yPos[i]) + (yPos[i] - yPos[i+1])) / 2;
YDPos = yPos[i] - (Math.round(picHeight) / 2);
document.write(dotCode.replace(/dot_id/, i).replace(/pic_height/, Math.ceil(picHeight)).replace(/pic_alt/, datas[i]));
eval(leftCode.replace(/obj_id/, 'p' + i) + (minXpos + i));
eval(topCode.replace(/obj_id/, 'p' + i) + YDPos);
}
</script>
<body bgcolor="#FFFFFF">
</body>
</html>
<!-- Script Size: 4.67 KB -->