How to Create JavaScript Word Cloud Chart — Tutorial for Web Developers

Wondering how to make a beautiful interactive Word Cloud using JS? Then you’re in the right place! In this data visualization tutorial, I’ll guide you through the entire development process, demonstrating it’s easier to create a JavaScript word cloud chart for an HTML5 app or web page than you might think!

Also known as tag clouds, word clouds represent a popular visual technique designed to reveal how often tags (or basically, any words) are mentioned in a given text body. Essentially, the word cloud chart type leverages diverse colors and sizes to display at a glance different levels of relative prominence.

Now that we’ve got an idea of what a word cloud is, let’s get down to learning how to quickly code one using JavaScript!

Building Basic JavaScript Word Cloud

Generally speaking, there are four basic steps to create a chart of any type using JavaScript. Just follow them, and it won’t take you long to make your text data visualization look like this:

1. Create an HTML page

First of all, create an HTML page where your JavaScript word cloud chart will appear. It has to be as follows:

The container that you see in the <body> section is intended for your future chart. The width and height parameters are responsible for the chart size, and you can specify them in percentages or in pixels to make the chart fill as much page space as you want.

2. Reference all necessary files

Then, add the necessary AnyChart JavaScript charting library links into the <head> section in the <script> tags:

3. Put together the data

The most valuable part of any chart is data. So you should always carefully choose the chart type depending on exactly what you want to visualize and for what purpose. Visit Chartopedia, a handy tool that will tell you more about each chart type and how to use one.

In the present case, a tag (word) cloud chart will be used to demonstrate the 15 most spoken languages. Go to Wikipedia: List of languages by total number of speakers and obtain the data from there:

The magic is that all the tags in a word cloud chart will get their size and color automatically after you write the values and put the languages in categories in the data object:

4. Write the JS word cloud chart code

Now, add the anychart.onDocumentReady() function to be executed when the page is ready:

After that, add the data into the function, create the tag cloud chart, set its title and legend, and just command to display it:

The JavaScript word (tag) cloud chart code should be put in the <script> tag from the second step. And that's it!

Yay! You did it! Check out the beautiful JS word cloud sample you’ve made:

Customize Word Cloud Chart Appearance

If you want to change how your JavaScript word cloud chart look, you can easily modify it. Visit the Word Cloud Chart settings and Word Cloud Chart gallery pages to see the instruction on and examples of how it can be done.

In the meantime, let’s makes some visual changes to the tag cloud built along the tutorial.

Tooltips in a word cloud

You must have noticed that in the data object, the values are in millions and billions. But it may be hard to clearly perceive such long numbers in a visual way. Therefore, it would be good to properly configure the chart tooltips with the help of the formatting parameters list:

Now the JS word cloud sample tooltips read better, don’t they?

Angles of the tags

If you want your JavaScript word cloud to look sort of more сhaotic, you can simply change the angles at which the tags are arranged. For example:

And the JS word cloud chart sample becomes a little bit wild:

Word cloud interactivity

You may also want to link tags to some web pages. If so, use the listen() method to add an event listener to your word cloud chart. In the given case, clicking on a word will lead to its Wikipedia page opening, which means you will be able to find more information about every language:

Here is your final interactive JS word cloud chart:


You see there is nothing difficult in creating beautiful interactive JavaScript word cloud charts for web pages and applications, in particular using the AnyChart JS (HTML5) charting library for data visualization.

For more information, check the official AnyChart JS Charts website. The Chart Documentation and Chart API Reference sections will help you make and tune your JavaScript charts in a way you prefer, and you can freely play with the code of the charts on the Chart Playground.

You are also welcome to check out the other basic JavaScript chart tutorials on our blog.

Now it’s time for your questions! Feel free to ask them in the comments below or by contacting our Support Team.

Originally published at, where you can find a version with interactive charts and code with syntax highlighting, on April 30, 2019.

Cross-platform JavaScript/HTML5 data visualization solutions, flexible JS charts libraries & Qlik Sense extensions for all your dataviz needs: