External javascript file

External javascript file

  

Hi,

I've downloaded https://github.com/timdream/wordcloud2.js (to create a wordcloud) and put that js file to the resources (deploy to target dir). Then I put an AddJavscriptTag action in the preparation of the screen. I added a container to the screen with id "my_canvas" and then I tried (in onclick extended propery): 

"WordCloud(document.getElementById('my_canvas'), {[['Cent', 12],['Euro', 6]]}); return false;"

It is not working though. Do I miss something?

Regards, Harry

Hi Harry,

I guess it's not getting the right Id for the element since the name that you give to the container is not the exact Id in the html.

Try this:

"WordCloud(document.getElementById('" + my_canvas.Id + '), {[['Cent', 12],['Euro', 6]]}); return false;"

Cheers,

José

Hi José,

I thought that GetElementById needed an Id and if I give a container an id ('my_canvas') that's would the right one. I tried your code though (added an " that was missing I think) but it still doesn't work.

Regards, Harry

Hi Harry,

Yes, It was missing an "...

Is there any javascript error when you click to execute that code? What is the error? Can you share a sample oml?

Cheers,

José

José,

No error, but no result (but 'strange' looking screen). OML attached.

Regards, Harry

Solution

Hi Harry,

Here it goes the oml back to you. Two things that I changed:

  • The json that is the parameter to the WordCloud function was missing a list attribute:
"WordCloud(document.getElementById('" + my_canvas.Id + "'), {list: [['Cent', 12],['Euro', 6]]});"
  • The container element should be of type canvas:

Cheers,

José

Solution

José,


Thank you so much! Do you know where I can find such things in the docs? ostagname was new to me.Now I have to pass a list from a server entity as the list in the js script, and I have a working tagcloud. Great.

Regards, Harry   

Hi Harry,

I actually found out about the ostagname here in the forums. :)

Glad to help.

Cheers,

José

Hi José.

I want to replace the list in the js with contents of an entity, but this gives an error (Operand cannot be applied between text and list:

"WordCloud(document.getElementById('" + my_canvas.Id + "'), {list:" + GetWoorden.List + "});"

what is the proper way to do this?

Regards, Harry

Hello Harry,

The easier way (not the more performing, probably), is to iterate the list (in logic) and construct the string you have to use as argument to the action.

Cheers

Eduardo Jauch

Hi,

I tried it, but I cannot get it to work. I (in an action) assign the values to the varWoord var and (debugged it) the value is:

"['Brievenbus',23],['Postbus',34]"

Then in the same action I use a RunJavascript action with:

"WordCloud(document.getElementById('" + my_canvas.Id + "'), {list:[" + varWoord + "]});return false;"

and after that an Ajax refresh of the my_canvas. 

Nothing happens (except a 'flickering' of the screen (so something happens I guess)).

Any ideas why this is not working?

Regards, Harry

Solverd. Using an AjaxSubmit did the trick!

Regards, Harry

Hello Harry,

Yes. If you use a submit, things would not work unless the logic were in the preparation.

Please, mark Jose's answer as the correct one. As it is the answer to the original question :)

Cheers,

Eduardo Jauch