wvengen / d3-wordcloud

Plug-and-play wordcloud with D3
MIT License
81 stars 66 forks source link
d3 js wordcloud

Easy Word Cloud using D3

There is an amazing D3 wordcloud plugin for creating beautiful wordclouds. But it's not trivial for everyone to put it to use. This plugin makes it easy to create such a wordcloud.

Usage

A simple html page with a wordcloud might contain:

<html>
  <head>
    <title>Word Cloud</title>
    <script src="https://github.com/wvengen/d3-wordcloud/raw/master/lib/d3/d3.js"></script>
    <script src="https://github.com/wvengen/d3-wordcloud/raw/master/lib/d3/d3.layout.cloud.js"></script>
    <script src="https://github.com/wvengen/d3-wordcloud/raw/master/d3.wordcloud.js"></script>
  </head>
  <body>
    <div id='wordcloud'></div>
    <script>
      d3.wordcloud()
        .size([800, 400])
        .selector('#wordcloud')
        .words([{text: 'word', size: 5}, {text: 'cloud', size: 15}])
        .start();
    </script>
  </body>
</html>

That's all! The following properties are accepted:

In addition to this, the following d3-cloud properties are accepted:

Extensions

.onwordclick(function(d, i) {
  window.location = "https://www.google.co.uk/search?q=" + d.text;
})

Links