Curve: Difference between revisions

From JSXGraph Wiki
No edit summary
No edit summary
Line 6: Line 6:
* 'polar': polar curves
* 'polar': polar curves


== Function plotter - curveType:'plot' ==
= Function plotter - curveType:'plot' =
First, we initialize the board and set axes:
First, we initialize the board and set axes:
<source lang="javascript">
<source lang="javascript">
Line 25: Line 25:
</html>
</html>


==
As input data a curve needs 5 parameters:
As input data a curvve 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:
* the term for the x-component: It can be the expression for a variable like a simple "x", or a function returning the identity:
<source lang="javascript">
<source lang="javascript">
Line 63: Line 62:
</html>
</html>


== Plotting data - curveType:'graph' ==
= Plotting data - curveType:'graph' =
If the first componment of the input data consists of an data array, the curvveType is set to "graph". The second parameter (the y-component) can be a data array, but it also can be a function term.
If the first componment of the input data consists of an data array, the curvveType is set to "graph". The second parameter (the y-component) can be a data array, but it also can be a function term.
<source lang="javascript">
<source lang="javascript">
Line 76: Line 75:
axisx = b3.createElement('axis', [[1,0], [0,0]], {});
axisx = b3.createElement('axis', [[1,0], [0,0]], {});
axisy = b3.createElement('axis', [[0,1], [0,0]], {});
axisy = b3.createElement('axis', [[0,1], [0,0]], {});
var dataX = [1,2,3,4,5,6,7,8];
var dataY = [0.3,4.0,-1,2.3,7,9,8,9];
b3.createElement('curve', [dataX,dataY]);
b3.createElement('curve', [dataX,dataY]);
</script>
</script>
</html>
</html>

Revision as of 09:08, 19 September 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:'plot'

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', [[1,0], [0,0]], {});
axisy = b.createElement('axis', [[0,1], [0,0]], {});

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:'plot'});

Plotting data - curveType:'graph'

If the first componment of the input data consists of an data array, the curvveType is set to "graph". The second parameter (the y-component) can be a data array, but it also can be a function term.

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]);