JSXGraph Example: Intersection x-Axis II

Last modified by Anna Paul-Hasenfuss on 19.06.2025

This example shows how user input can be stored in an ONYX gap in the JSX graphic.

Beispiel3 - Vorschau der Aufgabe_de.png Beispiel3 - Abgegebene Aufgabe_de.png

Question as it is seen by the learner                                                            Question evaluation plus hand-in       

 Editor - JSX an Lücke_de.png

To create this example, proceed as follows:

Create a text entry interaction. Define the task and generate the required gaps. In this example, only one gap is used for the JSX object. Make a note of the gap's ID. 

In the example, learners will not see the gap when they open the task. It only appears once the task has been handed in.

 

Beispiel3 - Aufgabenstellung mit Lücke_de.png

Add a JSXGraph object by clicking on the Icon_JSX.png icon. Now, change the JavaScript code in the dialog as follows:

document.getElementById({GAP_1}).setAttribute('hidden', 'hidden');
var brd=JXG.JSXGraph.initBoard('JSX_CONTAINER_ID',{axis:true, boundingbox:[-5, 5, 5, -5]});
var x=0;
let p=brd.create('point', [x, 0], {name:'P'});  
p.on('drag', function() {setOnyxGapValue({GAP_1}, p.X().toFixed(1));});

Explanations of the used code

The document.getElementById() method points to the object with the specified identifier (in this case, the Onyx gap GAP_1) and then uses the setAttribute() method to ensure that this gap is not visible to the learner but is initially “hidden.”

The JXG.JSXGraph.initBoard() method creates the field for the graphic.

The option axis or boundingbox adds an axis to the field or determines the boundary coordinates of the displayed part of the field.

Warning

Please note: Do not change the name 'JSX_CONTAINER_ID', as this is required by ONYX.

The method brd.create() with the identifier 'point' is used to draw a point with the given coordinates and a given name which is displayed in the graphic at the beginning.

The method brd.create() with the identifier 'button' is used to create a button. The button title and a method for accepting the input from the gap are passed in the arguments.

Information

The user's input in the graphic is only accepted by Onyx if the user applies the created button in the graphic. Make sure you explicitly point this out to your learners.

The method setOnyxGapValue() writes the second argument (here the x-coordinate of point p) into the Onyx gap specified by the first argument (here the Onyx gap with the identifier GAP_1). Once the task has been submitted, ONYX can check whether the user's action within the JSXGraph board has led to a correct solution.

Warning

You should be aware that learner actions shown in the graphic are subject to inaccuracy.

The last line p.on('drag', function() {setOnyxGapValue({GAP_1}, p.X().toFixed(1));}); automatically transfers the value to the gap when the point is moved.

Alternatively, you can display a button in the graphic that must be clicked to confirm the moved point before it is transferred to the gap. If this is the case, use the following code instead of the last line:

const butt = brd.create('button', [2, 3, "Punkt bestätigen", function(){setOnyxGapValue({GAP_1}, p.X()); }],{fixed:true});

Beispiel3 - JSX-Objekt anlegen_de.png

Beispiel3 - Korrekte Lösung anpassen_de.png

Check your details in the preview and save the task.Beispiel3 - Vorschau der Aufgabe_de.png