Curve: Difference between revisions
A WASSERMANN (talk | contribs) No edit summary |
A WASSERMANN (talk | contribs) No edit summary |
||
Line 10: | Line 10: | ||
<source lang="javascript"> | <source lang="javascript"> | ||
var b = JXG.JSXGraph.initBoard('jxgbox', {originX: 200, originY: 200, unitX: 20, unitY: 20}); | var b = JXG.JSXGraph.initBoard('jxgbox', {originX: 200, originY: 200, unitX: 20, unitY: 20}); | ||
axisx = b.createElement('axis', [[ | axisx = b.createElement('axis', [[0,0], [1,0]], {}); | ||
axisy = b.createElement('axis', [[0, | axisy = b.createElement('axis', [[0,0], [0,1]], {}); | ||
</source> | </source> | ||
<html> | <html> | ||
Line 20: | Line 20: | ||
<script type="text/javascript"> | <script type="text/javascript"> | ||
var b = JXG.JSXGraph.initBoard('jxgbox', {originX: 200, originY: 200, unitX: 20, unitY: 20}); | var b = JXG.JSXGraph.initBoard('jxgbox', {originX: 200, originY: 200, unitX: 20, unitY: 20}); | ||
axisx = b.createElement('axis', [[ | axisx = b.createElement('axis', [[0,0], [1,0]], {}); | ||
axisy = b.createElement('axis', [[0, | axisy = b.createElement('axis', [[0,0], [0,1]], {}); | ||
</script> | </script> | ||
</html> | </html> | ||
Line 56: | Line 56: | ||
<script type="text/javascript"> | <script type="text/javascript"> | ||
var b2 = JXG.JSXGraph.initBoard('jxgbox2', {originX: 200, originY: 200, unitX: 20, unitY: 20}); | var b2 = JXG.JSXGraph.initBoard('jxgbox2', {originX: 200, originY: 200, unitX: 20, unitY: 20}); | ||
axisx = b2.createElement('axis', [[ | axisx = b2.createElement('axis', [[0,0], [1,0]], {}); | ||
axisy = b2.createElement('axis', [[0, | axisy = b2.createElement('axis', [[0,0], [0,1]], {}); | ||
b2.createElement('curve', ['x',function(x){return Math.sin(x);},'x',-Math.PI,4*Math.PI],{curveType:'graph'}); | b2.createElement('curve', ['x',function(x){return Math.sin(x);},'x',-Math.PI,4*Math.PI],{curveType:'graph'}); | ||
</script> | </script> | ||
Line 73: | Line 73: | ||
<script type="text/javascript"> | <script type="text/javascript"> | ||
var b4 = JXG.JSXGraph.initBoard('jxgbox4', {originX: 200, originY: 200, unitX: 20, unitY: 20}); | var b4 = JXG.JSXGraph.initBoard('jxgbox4', {originX: 200, originY: 200, unitX: 20, unitY: 20}); | ||
axisx = b4.createElement('axis', [[ | axisx = b4.createElement('axis', [[0,0], [1,0]], {}); | ||
axisy = b4.createElement('axis', [[0, | axisy = b4.createElement('axis', [[0,0], [0,1]], {}); | ||
p = b4.createElement('point',[1,4],{style:6,name:'A'}); | p = b4.createElement('point',[1,4],{style:6,name:'A'}); | ||
b4.createElement('curve', ['x',function(x){return p.X()*Math.sin(x);},'x'],{curveType:'graph',dash:1}); | b4.createElement('curve', ['x',function(x){return p.X()*Math.sin(x);},'x'],{curveType:'graph',dash:1}); | ||
Line 93: | Line 93: | ||
<script type="text/javascript"> | <script type="text/javascript"> | ||
var b3 = JXG.JSXGraph.initBoard('jxgbox3', {originX: 200, originY: 200, unitX: 20, unitY: 20}); | var b3 = JXG.JSXGraph.initBoard('jxgbox3', {originX: 200, originY: 200, unitX: 20, unitY: 20}); | ||
axisx = b3.createElement('axis', [[ | axisx = b3.createElement('axis', [[0,0], [1,0]], {}); | ||
axisy = b3.createElement('axis', [[0, | axisy = b3.createElement('axis', [[0,0], [0,1]], {}); | ||
b3.createElement('point',[1,4],{style:6,name:'A'}); | b3.createElement('point',[1,4],{style:6,name:'A'}); | ||
var dataX = [-3,1,2,3,4,5,6,7,10,12]; | var dataX = [-3,1,2,3,4,5,6,7,10,12]; |
Revision as of 15:20, 28 November 2008
There are various possibilities to display curves and plots. JSXGraph supports the following curve types which can be set by changing the property "curveType". In many cases JSXGraph can guess the curveType from the input parameters, but sometimes the curveType has to be set explicitly.
- 'plot': function plotter
- 'parameter': parameter curves.
- 'graph': data plot
- 'polar': polar curves
Function plotter - curveType:'graph'
First, we initialize the board and set axes:
var b = JXG.JSXGraph.initBoard('jxgbox', {originX: 200, originY: 200, unitX: 20, unitY: 20});
axisx = b.createElement('axis', [[0,0], [1,0]], {});
axisy = b.createElement('axis', [[0,0], [0,1]], {});
As input data a curve needs 5 parameters:
- the term for the x-component: It can be the expression for a variable like a simple "x", or a function returning the identity:
createElement('curve', ['x', ...
createElement('curve', [function(x) {return x;}, ...
- the term for the y-component: it can be a JavaScript function having one input parameter, or an expression in GEONExT syntax.
createElement('curve', ['x', 'Sin(x)', ...
createElement('curve', ['x', function(x){return Math.sin(x);}, ...
- the variable for the GEONExT-syntax. For function plotting it has to be the same as the first input parameter.
createElement('curve', ['x', 'Sin(x)', 'x', ...
createElement('curve', ['x', function(x){return Math.sin(x);}, 'x', ...
- The last two parameters are optional and can contain constants or functions which determine the interval of the x-component in which the graph is shown.
If these parameters are not given, the graph is plotted from the left border to the right border.
createElement('curve', ['x', 'Sin(x)', 'x', -Math.PI,4*Math.PI]
createElement('curve', ['x', function(x){return Math.sin(x);}, 'x',-Math.PI,4*Math.PI]
Together, the code looks like this:
b.createElement('curve', ['x',function(x){return Math.sin(x);},'x',-Math.PI,2*Math.PI],{curveType:'graph'});
Dynamic function graphs
The terms for the x-component and for the y-component can also depend on another element. This can be a JSXGraph element, but it can also be the value of a DOM element. Here, we show the sine curve sin(x) multiplied by the x-component of the point "A".
p = b.createLement('point',[1,1],{style:6,name:'A'});
b.createElement('curve', ['x',function(x){return p.X()*Math.sin(x);},'x'],{curveType:'graph',dash:1});
Plotting data - curveType:'plot'
If the first component of the input data consists of an data array, the curveType is set to "plot". The second parameter (the y-component) can be a data array, but it also can be a function term.
p = b.createElement('point',[1,4],{style:6,name:'A'});
var dataX = [1,2,3,4,5,6,7,8];
var dataY = [0.3,4.0,-1,2.3,7,9,8,9];
b.createElement('curve', [dataX,dataY],{strokeColor:'red',strokeWidth:3});
b.createElement('curve', [dataX,'X(A)*Sin(x)*x','x'],{strokeColor:'blue',strokeWidth:3,dash:1});