Even simpler function plotter: Difference between revisions
From JSXGraph Wiki
A WASSERMANN (talk | contribs) No edit summary |
A WASSERMANN (talk | contribs) No edit summary |
||
Line 2: | Line 2: | ||
<input type="text" id="input" value="sin(x)*x"> | <input type="text" id="input" value="sin(x)*x"> | ||
<input type="button" value="plot" onClick="plotter()"> | <input type="button" value="plot" onClick="plotter()"> | ||
<input type="button" value="clear all" onClick="clearAll()"> <br /> | |||
<input type="button" value="add tangent" onClick="addTangent()"> | <input type="button" value="add tangent" onClick="addTangent()"> | ||
<input type="button" value="add | <input type="button" value="add Derivative" onClick="addDerivative()"> | ||
</form> | </form> | ||
</html> | </html> |
Revision as of 14:10, 15 July 2010
The underlying JavaScript code
<input type="text" id="input" value="sin(x)*x">
<input type="button" value="plot" onClick="plotter()">
<input type="button" value="clear all" onClick="clearAll()">
var board = JXG.JSXGraph.initBoard('jxgbox', {boundingbox:[-5,8,8,-5], axis:true});
function plotter() {
var t = JXG.GeonextParser.geonext2JS(document.getElementById('input').value);
var f = new Function('x','var y = '+t+'; return y;');
board.create('functiongraph',[f,
function(){
var c = new JXG.Coords(JXG.COORDS_BY_SCREEN,[0,0],board);
return c.usrCoords[1];
},
function(){
var c = new JXG.Coords(JXG.COORDS_BY_SCREEN,[board.canvasWidth,0],board);
return c.usrCoords[1];
}
]);
}
function clearAll() {
JXG.JSXGraph.freeBoard(board);
board = JXG.JSXGraph.initBoard('jxgbox', {boundingbox:[-5,8,8,-5], axis:true});
}