Word Cloud

Note: See our Word Cloud Gallery for inspiration on all the different word cloud possibilities.

Word Cloud Type

In the chart object, add a type attribute. Set the value to wordcloud. A basic word cloud with text data looks like this:

{
  type: 'wordcloud'
}
https://app.zingsoft.com/demos/embed/M4FXBNZ7
https://app.zingsoft.com/demos/embed/M4FXBNZ7

Data

There are two ways to provide the data for your word cloud: the text attribute and the words array.

text Attribute

You can provide the desired text, and ZingChart will aggregate the data for you. Create an options object, and add a text attribute. Provide your text data as a string value.

options: {
  text: "text data..."
}

words Array

Alternatively, you can provide each word with an associated word count or weight (how little or often you want the specific word to appear). Create an options object, and add a words array. Inside the array, create an object for each word.

Inside each object, add a text attribute. Provide your word as a string value. Next, add a count attribute. Provide the word count as a number value.

options: {
  words: [
    {
      text: "word1",
      count: val1
    },
    {
      text: "word2",
      count: val2
    },
    ...
    {
      text: "wordN",
      count: valN
    }
  ]
}
https://app.zingsoft.com/demos/embed/MTV1Q4E1
https://app.zingsoft.com/demos/embed/MTV1Q4E1

Chart-Specific Properties

You can customize how the word cloud is filtered, positioned, and styled within the options object.

Note: Refer to the options JSON Configuration page for a full attribute list.

Filtering

Token

By default, ZingChart analyzes your data string per word. To change the analysis to characters, use the token attribute and set the value to word (default) or character.

{
    options: {
    token: 'character' // 'word'
  }
}
https://app.zingsoft.com/demos/embed/WDUE5IPZ
https://app.zingsoft.com/demos/embed/WDUE5IPZ

Minimum Length

Use the min-length attribute to filter out words below a specified minimum length. Provide a number value.

{
    options: {
    minLength: 4
  }
}
https://app.zingsoft.com/demos/embed/DDQN1UWX
https://app.zingsoft.com/demos/embed/DDQN1UWX

Ignore Words

Use the ignore array to define words to be excluded from the word cloud. Provide the values as strings inside the array.

{
    options: {
    ignore: ['establish', 'this']
  }
}
https://app.zingsoft.com/demos/embed/VO6YNVOH
https://app.zingsoft.com/demos/embed/VO6YNVOH

Maximum Items

Use the max-items attribute to set a limit to the number of words displayed in the word cloud. Provide a number value.

{
    options: {
    maxItems: 10
  }
}
https://app.zingsoft.com/demos/embed/UX10A43B
https://app.zingsoft.com/demos/embed/UX10A43B

Normalize

Use the normalize attribute to ignore letter casing when counting words. For example, in the demo below "Young" and "young" would be counted as the same word.

{
  options: {
    normalize: true
  }
}
https://app.zingsoft.com/demos/embed/0B3DW32N
https://app.zingsoft.com/demos/embed/0B3DW32N

Positioning

Aspect

Use the aspect attribute to change the layout of the word cloud. Enter a value of spiral (default), flow-center, or flow-top.

{
    options: {
    aspect: 'flow-center' // 'spiral' | 'flow-top'
  }
}
https://app.zingsoft.com/demos/embed/9W06OZH8
https://app.zingsoft.com/demos/embed/9W06OZH8

Rotate

Use the rotate attribute to rotate every other word in the cloud by 90 degrees. Provide a boolean value: true or false (default).

{
    options: {
    rotate: true // false
  }
}

Step Angle and Radius

Use the step-angle and step-radius attributes to set the step angle and/or radius. Provide number values.

{
  options: {
    stepAngle: 30,
    stepRadius: 30,
  }
}
https://app.zingsoft.com/demos/embed/SU7WXX2Q
https://app.zingsoft.com/demos/embed/SU7WXX2Q

Font Size

Use the max-font-size and min-font-size to define the maximum and/or maximum font sizes of the words displayed in the word cloud. Provide number or pixel values.

{
  options: {
    maxFontSize: 50,
    minFontSize: 10
  }
}
https://app.zingsoft.com/demos/embed/BEKJXGAQ
https://app.zingsoft.com/demos/embed/BEKJXGAQ

Font Color

Use the color-type attribute to select the type of color scheme to be applied to the word cloud: random (default), color, or palette.

Color

When color-type is set to color, use the color attribute to set a single font color.

{
  options: {
    colorType: 'color',
    color: '#4CAF50'
  }
}
https://app.zingsoft.com/demos/embed/6VLSV91M
https://app.zingsoft.com/demos/embed/6VLSV91M

Palette

When color-type is set to palette, use the palette array to specify the font color palette. Provide the color values as strings inside the array.

{
  options: {
    colorType: 'palette',
    palette: ['#2196F3', '#3F51B5', '#42A5F5', '#5C6BC0', '#64B5F6', '#7986CB', '#90CAF9', '#9FA8DA', '#BBDEFB', '#C5CAE9']
  }
}
https://app.zingsoft.com/demos/embed/LAHSWQ9O
https://app.zingsoft.com/demos/embed/LAHSWQ9O

Tokens

Word clouds use the following tokens:

Token Description
%hits The number of times that the word occurs in the cloud.
%text The selected word in the cloud.

Note: For more information on tokens, see our ZingChart Tokens Tutorial.

Further Customization

Use the style object to further style your word cloud. You can add backgrounds and borders, as well as turn on the hover state and tooltip features.

Note: Refer to the style JSON page for a full attribute list.

https://app.zingsoft.com/demos/embed/8O4U9I14
https://app.zingsoft.com/demos/embed/8O4U9I14

Interactions

To enable some interactivity on click of a word in the wordcloud, use the label_click event.

https://app.zingsoft.com/demos/embed/CYGEI9F5
https://app.zingsoft.com/demos/embed/CYGEI9F5