Preamble javascript and jsxgraph

14 views
Skip to first unread message

Will Morgan

unread,
Sep 23, 2025, 4:50:35 AMSep 23
to numbas...@googlegroups.com
Hi all,

I am having an issue with some pre-existing questions. In our team we have copied these from elsewhere and then adapted them to our purposes. I say this just to caveat that I am very very much a novice in javascript and need any explanations to be  pretty didactic and at a basic level.


It is a question about Histograms. It appears that the histogram is generated from some javascript in the "preamble" section under "extensions and scripts". It used to work and now it just doesn't produce any graph. We have changed nothing in the question in the intervening time. I have tried reading the help file on jsxgraph and it looks like what this is doing is more complicated than the examples given and I can't really get my head round how it should work.

Any idea why the graph has disappeared and what we can do to make it reappear?!

Cheers,

Will

Dr Will Morgan
Academic Skills Adviser (Maths)
301 Academic Skills Centre
Student & Academic Services
University of Sheffield
301 Glossop Road
Sheffield, S10 2HL

https://www.sheffield.ac.uk/mash
https://www.sheffield.ac.uk/academic-skills

My working days are Tuesday  (9am-6pm), Wednesday (8:30am-3pm) and Thursday (9am-4pm).

Ben Brawn

unread,
Sep 23, 2025, 8:36:13 AMSep 23
to Numbas Users
Hi Will, 
I'm not sure if they stopped working with the update of numbas or if it was even earlier, but I can't figure out how to get them to work either (this javascript mess is a copy of a question of mine, or maybe they share a common ancestor). Maybe someone else can shed some light, or suggest a nicer way to do it.

Christian Lawson-Perfect

unread,
Sep 23, 2025, 9:50:58 AMSep 23
to numbas...@googlegroups.com
The problem is that Numbas doesn't use jQuery any more, so the $() function doesn't exist.
You can fix your question by changing $(question.display.html).find('#dragpoint').append(div); to question.display.html.querySelector('#dragpoint').append(div);

But I'd like to encourage people not to make JSXGraph diagrams in the preamble, now that you can build them as question variables.
I've made another copy of the question where I've done that: https://numbas.mathcentre.ac.uk/question/share/view/8eb577cf-566b-4331-a723-a7b6a72bc0db

The benefit of defining a diagram as a variable is that it doesn't rely on fiddly JavaScript things, and you don't have to think about things like how the state of interactive diagrams gets saved and restored - the extension can take care of it for you.

--
You received this message because you are subscribed to the Google Groups "Numbas Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to numbas-users...@googlegroups.com.
To view this discussion, visit https://groups.google.com/d/msgid/numbas-users/7766b287-7fa8-416e-8c26-ece62d348133n%40googlegroups.com.

Will Morgan

unread,
Sep 23, 2025, 9:55:14 AMSep 23
to numbas...@googlegroups.com
Thank you so much Christian. I will look through this and digest!

Cheers,

Will


Reply all
Reply to author
Forward
0 new messages