timdream / wordcloud2.js

Tag cloud/Wordle presentation on 2D canvas or HTML

Home Page:https://wordcloud2-js.timdream.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

nothing is being displayed in div

ORESoftware opened this issue · comments

I have this:

<div id="my_canvas"></div>

and then this js call:

<script>
  WordCloud(document.getElementById('my_canvas'), {list: [['foo', 3], ['bar', 5]]});
</script>

the WordCloud() function gets called, but nothing gets displayed, weird

@ORESoftware

You need to initialize both a canvas and an HTML container!

<div id="my_container"></div>
<canvas id="my_canvas"></canvas>
<script>
  WordCloud([
    document.getElementById('my_canvas'),
    document.getElementById('my_container'),
  ], {list: [['foo', 3], ['bar', 5]]});
</script>

This works!

Note: Order is important here.

  • HTML should be div first.
  • WordCloud call must initialize canvas element first.

HTML Element appears to be built from the Canvas element. You can have a canvas without html, but to have an html cloud, you must have a canvas. Either element may be set to display: none.