# Difference between revisions of "Introduction"

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.

# 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>
<script type="text/javascript" src="jsxgraphcore.js"></script>


## 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>
<script type="text/javascript" src="http://jsxgraph.uni-bayreuth.de/distrib/jsxgraphcore.js"></script>


# 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', {originX: 100, originY: 100, unitX: 50, unitY: 50});
</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
originX positive integer 150 The horizontal position of the origin relative to the upper left corner of the drawing area.
originY positive integer 150 The vertical position of the origin relative to the upper left corner of the drawing area.
unitX positive integer 50 Amount of pixels determining one unit in user coordinates in horizontal direction.
unitY positive integer 50 Amount of pixels determining one unit in user coordinates in vertical direction.
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.