Solved

wordcloud2 help required

Posted on 2013-11-26
3
1,312 Views
Last Modified: 2013-11-26
I have downloaded wordcloud2.js to create my own word cloud (attached)

The included documentation is 'scant' to say the least

I have a page with the code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
	<style type="text/css">
	.wordcloud {
		float: left;
		position: relative;
		width: 500px;
		height: 150px;
		background-color: #eeeeee;
	}
	</style>
</head>
<body>
	<script type="text/javascript" src="wordcloud2.js"></script>
	<script type="text/javascript">
		WordCloud(document.getElementById('my_canvas'), { list: [['foo', 12], ['bar', 6]] } );
	</script>
	<canvas id="my_canvas" class="wordcloud"></canvas>
</body>
</html>

Open in new window


All I keep getting is the following error:

Line: 754
Error: Unable to get property 'dispatchEvent' of undefined or null reference

which refers to the following:

/* Send DOM event */
    var sendEvent = function sendEvent(el, type, cancelable, detail) {
      var evt = document.createEvent('CustomEvent');
      evt.initCustomEvent(type, true, cancelable, detail || {});
      return el.dispatchEvent(evt);
    };

Open in new window


It is highlighting the reference el.dispatchEvent(evt);

Has anyone had practical experience of using wordcloud or can fathom out it's implementation because I have been trying for hours with no joy.

Regards
wordcloud2.js
0
Comment
Question by:splanton
  • 2
3 Comments
 
LVL 30

Accepted Solution

by:
Alexandre Simões earned 500 total points
ID: 39677448
You are initializing it before the canvas element exists.

Try this:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
	<style type="text/css">
	.wordcloud {
		float: left;
		position: relative;
		width: 500px;
		height: 150px;
		background-color: #eeeeee;
	}
	</style>
</head>
<body>
        <canvas id="my_canvas" class="wordcloud"></canvas>
	<script type="text/javascript" src="wordcloud2.js"></script>
	<script type="text/javascript">
		WordCloud(document.getElementById('my_canvas'), { list: [['foo', 12], ['bar', 6]] } );
	</script>
</body>
</html>

Open in new window

0
 
LVL 2

Author Closing Comment

by:splanton
ID: 39677521
School boy error! Well spotted. I am off to kick myself round the car park. :)
0
 
LVL 30

Expert Comment

by:Alexandre Simões
ID: 39677527
If you were here you had to pay me a beer :)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Today I would like to talk about localizing (Internationalization) JavaScript applications. Introduction When creating an application that is going to be used by many people around the globe, it is important to remember that not everyone speak…
Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

947 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now