Curve

From JSXGraph Wiki
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

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.
  • 'polar': polar curves

Function graph

First, we initialize the board with axes:

var b = JXG.JSXGraph.initBoard('jxgbox', {boundingbox: [-10, 10, 20, -10], axis: true});

As input data a function graph needs between 1 and 3 parameters:

  • the term for the y-component: it can be a JavaScript function having one input parameter, or an expression in GEONExT syntax.
create('functiongraph', [function(x){return Math.sin(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.

create('functiongraph', [function(x){return Math.sin(x);},-Math.PI,4*Math.PI]

Together, the code looks like this:

b.create('functiongraph', [function(x){return Math.sin(x);},-Math.PI,2*Math.PI]);

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.create('point',[1,1],{size:4,name:'A'});
b.create('functiongraph', [function(x){return p.X()*Math.sin(x);}],{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.create('point',[1,4],{size:4,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.create('curve', [dataX,dataY],{strokeColor:'red',strokeWidth:3});
b.create('curve', [dataX,function(x){ return p.X()*Math.sin(x)*x;}],{strokeColor:'blue',strokeWidth:3,dash:1});