Alessandro Pietra
Alessandro Pietra

Reputation: 83

Wordcloud with wordcloud2.js

enter image description hereI need to create a word cloud for my site! I found a javascript tool named wordcloud2.js that performs what I want but... I found out that the .js doesn't display all the words I pass to the script in the array arr6. Does anyone know how to fix this problem? I've created (and passed to the script) an array of 20 elements(word + size) but only the first six are visualized. I don't know why...thanks in advance!

    var arr6=[ 
         ["Pear", "9"],
         ["Grape", "9"],
         ["Pine", "4"], 
         ["Banana", "6"],
         ["Lemon", "9"],
         ["Parigi", "5"],
         ["Apple", "5"]
         ["Mear", "4"],
         ["Torino", "4"],
         ["Mescola", "8"], 
         ["Gigi", "6"],
         ["Roma", "9"],
         ["Empoli", "5"],
         ["Mela", "5"]
         ["Alessandro", "9"],
         ["Imola", "4"],
         ["Hp", "4"], 
         ["Harry", "6"],
         ["Potter", "9"],
         ["Amsterdam", "5"],
         ["Como", "5"]
        ]; 
    var options = 
    { 

    list : arr6,      
    gridSize: Math.round(2 *     document.getElementById('canvas_cloud').offsetWidth / 1024),
    weightFactor: function (size) {
    return Math.pow(size, 2) *  document.getElementById('canvas_cloud').offsetWidth / 1024;
    }
  }

    WordCloud(document.getElementById('canvas_cloud'), options);

Upvotes: 0

Views: 3054

Answers (2)

KHB
KHB

Reputation: 656

WordCloud2.js api [https://github.com/timdream/wordcloud2.js/blob/gh-pages/API.md] also has a setting to not draw certain words below a set size. I can't remember if it has a default of 2 or not...

but the "minFontSize" may be set somewhere if you copied the settings from someone else.

but i'm pretty sure @Kaelin has the right idea that your array is just formatted incorrectly and getting truncated.

Upvotes: 0

Kaelin
Kaelin

Reputation: 31

You're missing some commas in your list array. It should be

    var arr6=[ 
     ["Pear", "9"],
     ["Grape", "9"],
     ["Pine", "4"], 
     ["Banana", "6"],
     ["Lemon", "9"],
     ["Parigi", "5"],
     ["Apple", "5"],
     ["Mear", "4"],
     ["Torino", "4"],
     ["Mescola", "8"], 
     ["Gigi", "6"],
     ["Roma", "9"],
     ["Empoli", "5"],
     ["Mela", "5"],
     ["Alessandro", "9"],
     ["Imola", "4"],
     ["Hp", "4"], 
     ["Harry", "6"],
     ["Potter", "9"],
     ["Amsterdam", "5"],
     ["Como", "5"]
    ]; 

Note the comma after the entry for Apple and the entry for Mela.

Upvotes: 3

Related Questions