Trying to dynamically load charts in Modx Revo but I'm getting an error


« Back to message list

Enter your email address to get email updates on this topic. You can stop receiving updates by clicking the link in the update email messages.

Posted by Smiffy on 18th October 2017
Hi

I've got my graph working perfectly on a stand alone page but when I copy it over to a chunk in Modx revo I get this error - 'unexpected token'.

The page (chunk) with the chart script on is loaded dynamically into a div using JQuery. The console shows there being no data.

The problem was that Modx uses [[$chunk_with_chart_on]] to call the script page which I will need to use to pull data from Mysql. Modx sees the [[1,2,3],[4,5,6]] data declaration and is expecting a chunk call.

I moved the data to a chunk and used spaces - [ [1,2,3],[4,5,6] ] and now the data is showing in the console but I'm now getting this error:

Uncaught ReferenceError: RGraph is not defined - console shows its this 'new RGraph.Bar({'

Everything else in the script looks to be okay, I shall test it with a very simple script to see if my script is the problem but I was wondering if there is something very simple I've missed - I suspect its something to do with jquery causing problems with the script running?

Any help would be very much appreciated

Thanks in advance

Steve :-)


Posted by Richard on 18th October 2017
Hi there,

Judging by the error your page is saying that the 'RGraph' variable does not exist. This would suggest that the RGraph scripts:

RGraph.common.core.js
RGraph.bar.js

Are not being loaded. If you'e dynamically loading the 'chunk' into a DIV then this could be why.

Try adding them to the main page - the one initially requested by the user - the one whose address the user types into the address bar of the browser.

Richard
Posted by Smiffy on 18th October 2017
Hi Richard,

Thanks for the prompt reply :-)

I've sorted it - on my test site I'd tweaked the positions of the images in the yaxis and commented out the halign: 'right' valign: 'center' options but didn't remove the ',' separator on the line above - DOH!!!!! It still worked fine on my test page but it fell over in Modx!!!!!!

A long time ago in a galaxy far away............. a wise man said if it falls over CHECK YOUR SPELLING before you doubt the validity of your code!!!!!

Thanks again for your help - RGraph is brilliant - I've spent hours trying to do this before I stumbled across RGraph - exactly what I needed. I can now generate the graph data from mysql, convert it to an image which I can then output to the user as a pdf.

:-)

Add a reply




« Back to message list