Introduction

From JSXGraph Wiki
Revision as of 11:30, 31 January 2013 by Michael (talk | contribs)

JSXGraph is a browser based library for interactive geometry, function plotting, graphs, and data visualization. It is completely written in JavaScript and everybody with a little experience with JavaScript shouldn't have problems using JSXGraph. Thanks to the dynamics of JavaScript JSXGraph is also very easy to extend and thanks to AJAX many other softwarepackages can be integrated.

If you have any question about JSXGraph or this documentation feel free to contact us.

Embed JSXGraph in a webpage

You need the following files:

You can either download these files and use the local copy or you can use the online version.

Usage of a local copy

If you want to include a local copy of JSXGraph in your HTML file then you have to write the following lines into the document head:

<head>
 <link rel="stylesheet" type="text/css" href="jsxgraph.css" />
 <script type="text/javascript" src="jsxgraphcore.js"></script>
</head>

Usage of the online copy

If you want to include the online of JSXGraph in your HTML file then you have to write the following lines into the document head:

<head>
 <link rel="stylesheet" type="text/css" href="http://jsxgraph.uni-bayreuth.de/distrib/jsxgraph.css" />
 <script type="text/javascript" src="http://jsxgraph.uni-bayreuth.de/distrib/jsxgraphcore.js"></script>
</head>


Include a drawing panel into the HTML

General creation of a JSXGraph board

If you want to use JSXGraph in most cases you want to draw something on a web page (although some algorithms that don't depend on visual elements are implemented they're by now not so numerous...). Before anything can be drawn, you'll have to create a board JSXGraph can draw on. To create a board we need a HTML element - usually a div-element is taken - with an ID attribute. Using this ID, we declare this element to be a drawing panel of JSXGraph:

<body>
[...]
<div id="box" class="jxgbox" style="width:200px; height:200px;"></div>
<script type="text/javascript">
 var board = JXG.JSXGraph.initBoard('jxgbox', {boundingbox: [-2, 2, 2, -2]});
</script>
[...]

This creates an empty drawing panel sized 200x200 pixels with the origin in the center of the box.

As already mentioned, originX and originY determine the origins position in screen coordinates relative to the upper left corner of the drawing box. In the above example the origin is in the center of the board with screen coordinates (250, 250) but has user coordinates - as origins should have - (0, 0). This is the only coordinate you give in screen coordinates - all the other data (e.g. coordinates when constructing a point, parameters when plotting a curve) should be given in user coordinate system. The options unitX and unitY determine the amount of pixels representing one unit in user coordinates. For the beginning these two numbers should be equal otherwise you'd get different zoom factors in x and y direction resulting in circles appearing as ellipses.

Instead of supplying values for originX, originY, unitX, unitY, you can define the user coordinate region shown on the drawing panel directly. The option for that is called boundingbox and is used like that:

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

The axis option just draws a standard x- and y-axis on the board and is used to visualize the bounding box:

The syntax of this option is pretty easy to understand: It takes an array with 4 numbers defining the most left, top, right, bottom point available on screen in user coordinates.

Various options to affect the initialisation of the board

Here are the other options explained together with the already mentioned in a small table:

Option Type Default value Explanation
boundingbox Array [-5, 5, 5, -5] The viewport of the board.
axis bool false If true, default axes are drawn on the board. To draw axes with special options set this to false and create them manually. See also Ticks.
grid bool false If true, a grid is drawn on the board.
showNavigation bool true If false, removes navigation menu from board.
showCopyright bool true If false, removes copyright message from board.
zoomfactor positive float 1.0 Sets zoom factor on the board.
zoomX positive float 1.0 Sets zoom factor in horizontal direction. The final zoom factor in this direction is this value multiplied with zoomfactor.
zoomY positive float 1.0 Sets zoom factor in vertical direction. The final zoom factor in this direction is this value multiplied with zoomfactor.