Highcharts Word Cloud Chart

In the previous chapters, we learned how to setup highcharts library and how to create a chart with required configurations using highcharts library in our webpage. Now, we will learn how to create a word cloud chart using highcharts library with examples.

Highcharts Word Cloud Chart Example

Following is the example of creating a word cloud chart by setting the required chart properties using highcharts library.

 

Live Preview

<html>

<head>

    <title>Highcharts Word Cloud Chart</title>

    <script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>

    <script src="https://code.highcharts.com/highcharts.js"></script>

    <script src="https://code.highcharts.com/modules/wordcloud.js"></script>

    <script type="text/javascript">

        $(function() {

            var text = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean bibendum erat ac justo sollicitudin, quis lacinia ligula fringilla. Pellentesque hendrerit, nisi vitae posuere condimentum, lectus urna accumsan libero, rutrum commodo mi lacus pretium erat. Phasellus pretium ultrices mi sed semper. Praesent ut tristique magna. Donec nisl tellus, sagittis ut tempus sit amet, consectetur eget erat. Sed ornare gravida lacinia. Curabitur iaculis metus purus, eget pretium est laoreet ut. Quisque tristique augue ac eros malesuada, vitae facilisis mauris sollicitudin. Mauris ac molestie nulla, vitae facilisis quam. Curabitur placerat ornare sem, in mattis purus posuere eget. Praesent non condimentum odio. Nunc aliquet, odio nec auctor congue, sapien justo dictum massa, nec fermentum massa sapien non tellus. Praesent luctus eros et nunc pretium hendrerit. In consequat et eros nec interdum. Ut neque dui, maximus id elit ac, consequat pretium tellus. Nullam vel accumsan lorem.';

            var lines = text.split(/[,\. ]+/g),

                data = Highcharts.reduce(lines, function(arr, word) {

                    var obj = Highcharts.find(arr, function(obj) {

                        return obj.name === word;

                    });

                    if (obj) {

                        obj.weight += 1;

                    } else {

                        obj = {

                            name: word,

                            weight: 1

                        };

                        arr.push(obj);

                    }

                    return arr;

                }, []);

            Highcharts.chart('container', {

                series: [{

                    type: 'wordcloud',

                    data: data,

                    name: 'Occurrences'

                }],

                title: {

                    text: 'Wordcloud of Lorem Ipsum'

                }

            });

        });

    </script>

</head>

<body>

    <div id="container"></div>

</body>

</html>

If you observe the above example, we created a word cloud chart by using highcharts library with required properties.

 

When we execute the above highcharts example, we will get the result like as shown below.

 

Highcharts word cloud chart example result

 

This is how we can create a word cloud chart using highcharts library with required properties. 

Topics Covered