Solved

wordcloud2 help required

Posted on 2013-11-26
3
1,465 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

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…
This article discusses how to implement server side field validation and display customized error messages to the client.
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…
Suggested Courses

617 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