Solved

wordcloud2 help required

Posted on 2013-11-26
3
1,275 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
Comment Utility
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
Comment Utility
School boy error! Well spotted. I am off to kick myself round the car park. :)
0
 
LVL 30

Expert Comment

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

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

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…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…

772 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

11 Experts available now in Live!

Get 1:1 Help Now