问题
I have a problem to make a dynamic graph from this library http://jsxgraph.uni-bayreuth.de/docs/symbols/Integral.html
== this will make f(x) = x^3
var c1 = board.create('functiongraph', [function (t) { return t*t*t; }]);
var i1 = board.create('integral', [[-1.0, 4.0], c1]);
but, how can i make function(t) depends from user input ? for example user input x^2+4x from texboxt and the code will generate this: var fx = $("#fx").val(); // fx = x^2 + 4x var c1 = board.create('functiongraph', [function (x) { return fx; }]);
回答1:
JSXGraph comes with its own parser JessieCode (see https://github.com/jsxgraph/JessieCode) which does exactly this. JessieCode reads Math syntax, i.e. x^2 is converted to x*x, and hands over an object which can be plotted by JSXGraph.
Here is your example realized with JessieCode:
var fx = $("#fx").val();
var f = board.jc.snippet(fx, true, 'x', true);
var c1 = board.create('functiongraph', [f]);
来源:https://stackoverflow.com/questions/23927046/how-to-make-a-dynamic-function-to-draw-integral-graph-from-user-input-with-jsxgr