Chart.js Word Clouds

Overview

Chart.js Word Clouds

NPM Package Github Actions

Chart.js module for charting word or tag clouds. Adding new chart type: wordCloud.

word cloud example

Related Plugins

Check out also my other chart.js plugins:

Install

npm install --save chart.js chartjs-chart-wordcloud

Usage

see Samples on Github

or at this Open in CodePen

Word Cloud

Data Structure

const config = {
  type: 'wordCloud',
  data: {
    // text
    labels: ['Hello', 'world', 'normally', 'you', 'want', 'more', 'words', 'than', 'this'],
    datasets: [
      {
        label: 'DS',
        // size in pixel
        data: [90, 80, 70, 60, 50, 40, 30, 20, 10],
      },
    ],
  },
  options: {},
};

Styling of elements

A word has the basic FontSpec styling options (family, color, ...). In addition it has several options regarding rotating the text.

Controller options:

https://github.com/sgratzl/chartjs-chart-wordcloud/blob/14ac8327c2209c0d8f89fdd6cd86d2b2d7daedce/src/controllers/WordCloudController.ts#L184-L193

Word element options:

https://github.com/sgratzl/chartjs-chart-wordcloud/blob/14ac8327c2209c0d8f89fdd6cd86d2b2d7daedce/src/elements/WordElement.ts#L3-L29

ESM and Tree Shaking

The ESM build of the library supports tree shaking thus having no side effects. As a consequence the chart.js library won't be automatically manipulated nor new controllers automatically registered. One has to manually import and register them.

Variant A:

import { Chart } from 'chart.js';
import { WordCloudController, WordElement } from 'chartjs-chart-wordcloud';

Chart.register(WordCloudController, WordElement);
...

new Chart(ctx, {
  type: WordCloudController.id,
  data: [...],
});

Variant B:

import { WordCloudChart } from 'chartjs-chart-wordcloud';

new WordCloudChart(ctx, {
  data: [...],
});

Development Environment

npm i -g yarn
yarn install
yarn sdks vscode

Common commands

yarn compile
yarn test
yarn lint
yarn fix
yarn build
yarn docs
Comments
  • core.js:6241 ERROR Error:

    core.js:6241 ERROR Error: "linear" is not a registered scale.

    I'm having the following question When I try to run the test code, there is a error with chrome

    Screenshots / Sketches 98C602B1-B072-4998-A3E3-8B84D217577D

    Context this is my test code . 266D439C-1EAB-44be-87CE-42D2ADB82EA1 6A9A3937-4EBC-40fb-8E61-ED9621E35A6D

    • Version: 2E850FD1-43AA-4635-84E1-5735EF7F1613

    • Browser: chrome Additional context

    question answered 
    opened by soislom 15
  • use with vue-chart-3

    use with vue-chart-3

    I'm having the following question... How to use chartjs-chart-wordcloud with vue-chart-3 without errors?

    main.ts - Vue render file
    
    import { WordCloudController, WordElement } from 'chartjs-chart-wordcloud'
    Chart.register(WordCloudController, WordElement)
    
    
    Vue component file
    <template>
                ...
                <div class="md:flex-1 w-full min-h-full">
                    <WordCloudChart :chartData="chartData" />
                </div>
                ...
    </template>
    
    <script lang="ts">
    import { computed, defineComponent, ref, watch, onMounted } from 'vue'
    import { ChartData } from 'chart.js'
    import { WordCloudChart } from "chartjs-chart-wordcloud";
    ...
    
    export default defineComponent({
        components: { WordCloudChart},
    ...
        setup(props) {
             ...
    
            const wordsValues = computed(() => {
                return words.value.map((d) => d.value)
            })
            
            const wordsTitles = computed(() => {
                return words.value.map((d) => d.key)
            })
    
            onMounted(() => {
                getdpWordCloudData()
            })
    
    
            ...
            const chartData = computed<ChartData<"wordCloud">>(() => (<ChartData<"wordCloud">><unknown>{
                labels: words.value.map((e) => e.key),
                datasets: [
                    {
                        label: "",
                        data: wordsValues.value,
                    }
                ]
            }));
    
            return {chartData}
        },
    })
    </script>
    

    I get this error on browser console:

           Uncaught (in promise) TypeError: Class constructor WordCloudChart cannot be invoked without 'new'
        at renderComponentRoot (runtime-core.esm-bundler.js:475:19)
        at ReactiveEffect.componentUpdateFn [as fn] (runtime-core.esm-bundler.js:4332:57)
        at ReactiveEffect.run (reactivity.esm-bundler.js:160:29)
        at setupRenderEffect (runtime-core.esm-bundler.js:4458:9)
        at mountComponent (runtime-core.esm-bundler.js:4241:9)
        at processComponent (runtime-core.esm-bundler.js:4199:17)
        at patch (runtime-core.esm-bundler.js:3791:21)
        at mountChildren (runtime-core.esm-bundler.js:3987:13)
        at mountElement (runtime-core.esm-bundler.js:3896:17)
        at processElement (runtime-core.esm-bundler.js:3868:13)
    
    help wanted question 
    opened by silvercent011 4
  • Uncaught TypeError: Cannot read property 'y' of undefined

    Uncaught TypeError: Cannot read property 'y' of undefined

    No chart drawn, exception thrown.

    To Reproduce I use Laravel Mix to build js assets. Used libs (package.json dependencies):

    "dependencies": {
            "@sgratzl/chartjs-esm-facade": "^3.0.0-alpha.21",
            "@ttskch/select2-bootstrap4-theme": "^1.3.4",
            "bootstrap": "4.5.3",
            "chart.js": "^3.0.0-beta.11",
            "chartjs-chart-wordcloud": "^3.0.0-beta.9",
            "datatables.net-bs4": "^1.10.23",
            "datatables.net-buttons-bs4": "^1.6.5",
            "datatables.net-colreorder-bs4": "^1.5.3",
            "datatables.net-fixedcolumns-bs4": "^3.3.2",
            "datatables.net-fixedheader-bs4": "^3.1.8",
            "datatables.net-keytable-bs4": "^2.6.0",
            "datatables.net-responsive-bs4": "^2.2.7",
            "datatables.net-rowgroup-bs4": "^1.1.2",
            "datatables.net-rowreorder-bs4": "^1.2.7",
            "datatables.net-scroller-bs4": "^2.0.3",
            "datatables.net-searchbuilder-bs4": "^1.0.1",
            "datatables.net-searchpanes-bs4": "^1.2.2",
            "datatables.net-select-bs4": "^1.3.1",
            "jqcloud2": "^2.0.3",
            "jquery": "3.5.1",
            "jszip": "^3.6.0",
            "owl.carousel": "2.3.4",
            "pdfmake": "^0.1.70",
            "popper.js": "1.16.1",
            "select2": "^4.0.13",
            "wordcloud": "^1.1.2"
        }
    

    HTML file:

    <div id="container" style="width: 75%">
        <canvas id="test-canvas"></canvas>
    </div>
    

    JS file, composed with webpack:

    import { WordCloudChart } from 'chartjs-chart-wordcloud';
    import { Chart, LinearScale } from 'chart.js';
    
    Chart.register(LinearScale);
    
    const words = [
                { key: 'word', value: 10 },
                { key: 'words', value: 8 },
                { key: 'sprite', value: 7 },
                { key: 'placed', value: 5 },
                { key: 'layout', value: 4 },
                { key: 'algorithm', value: 4 },
            ];
    
    const data = {
        labels: words.map((d) => d.key),
        datasets: [
            {
            label: '',
            data: words.map((d) => 10 + d.value * 10),
            },
        ],
    };
    
    new WordCloudChart(document.getElementById('test-canvas').getContext('2d'), {
        data: data,
        options: {
            title: {
                display: true,
                text: 'Chart.js Word Cloud',
            },
        },
    });
    

    Exception: image

    Place in code (i tried to use available fields of ctx object, but this leads to another error with fit property somewhere): image

    • Version: 3.0.0-beta.9
    • Browser: Google Chrome 88.0.4324.190 (64-bit)
    bug 
    opened by sergotail 4
  • Page freezes on init

    Page freezes on init

    On initialising and creating the chart instance, the webpage freezes, and has to be force closed

    To Reproduce

    1. Happening only on production

    Expected behavior

    Wordcloud should initialize and render

    Screenshots

    Context

    • Version: v3.0.0_Beta-7
    • Browser: Any

    Additional context

    bug 
    opened by supmanyu 4
  • Could not find the label and dataset value in click event

    Could not find the label and dataset value in click event

    options: {

        onClick: (e) => {
          
      const canvasPosition = ctx.helpers.getRelativePosition(e, ctx);
    

    }

    Getting below error

    core.mjs:6461 ERROR TypeError: Cannot read properties of undefined (reading 'getRelativePosition') at Chart.onClick (app.component.ts:37:42) at callback (helpers.segment.js:92:1) at Chart._handleEvent (chart.esm.js:6090:17) at Chart._eventHandler (chart.esm.js:6072:1) at listener (chart.esm.js:5952:1) at Chart.event (chart.esm.js:3214:1) at helpers.segment.js:28:1 at timer (zone.js:2561:1) at ZoneDelegate.invokeTask (zone.js:406:1) at Object.onInvokeTask (core.mjs:25444:1)

    bug invalid 
    opened by contact2vikas 3
  • React implementation

    React implementation

    I'm having the following question. How can this be included in a React project as a component. My problem is basically understanding how could I access the ctx (document.getElementById) from a React functional component. It is returning me null.

    Screenshots / Sketches

    This is my WordsCloud.js file for reference.

    const data = {
        labels: initialWords.map((d) => d.key),
        datasets: [
          {
            label: '',
            data: initialWords.map((d) => 10 + d.value * 10),
          },
        ],
      };
      const options = {
        title: {
          display: true,
          text: 'Chart.js Word Cloud',
        },
      };
      const ctx = document.getElementById('cloudmap').getContext('2d');
      const chart = new WordCloudChart(ctx, {
        data,
        options,
      });
      return (
        <div>
          <div>
            <canvas id='cloudmap'></canvas>
          </div>
          <chart />
        </div>
      );
    

    Context

    • Version:
    • Browser:

    Additional context

    question answered 
    opened by alvaroserrrano 3
  • Documentation on options

    Documentation on options

    In the documentation there is a basic example of the wordcloud plugin. What's missing for me is an explanation of how to use the options. For example, how can the colors and orientation of the words be changed? The supplied link to the source is not enough for me to see how the options parameter should be filled.

    question 
    opened by jansipke 2
  • Can I make sure all words always fit into canvas?

    Can I make sure all words always fit into canvas?

    I use word clouds with some data i can't make any assumption on its weigths distribution. It's also i don't know min and max possible weights and can only assume weights scale, for example, logarithmic. But as i understood, i have to scale weights myself before feeding data into word cloud chart. Like with line charts, scale may be changed automatically that so all the data fit on canvas. Is there some way to achieve similar behaviour in word cloud chart?

    Thanks for response!

    question 
    opened by sergotail 2
  • The CodePen example does not work

    The CodePen example does not work

    The codepen example does not work, the canvas stays blank. There is the following error message in the console:

    chartjs-chart-wordcloud@3:1 Uncaught TypeError: a.default is not a function
        at new s (chartjs-chart-wordcloud@3:1:1910)
        at bn.buildOrUpdateControllers (chart.js@3:13:91691)
        at bn.update (chart.js@3:13:92264)
        at bn.<anonymous> (chart.js@3:13:88470)
        at bn._doResize (chart.js@3:7:5357)
        at bn._resize (chart.js@3:13:89762)
        at bn.resize (chart.js@3:13:89353)
        at n (chart.js@3:13:98477)
        at chart.js@3:13:39499
        at chart.js@3:7:5247
    
    • Browser: tested in Chromium and Firefox
    bug 
    opened by JosephChataignon 1
  • We are getting an error

    We are getting an error "ERROR Error: Canvas is already in use. Chart with ID '2' must be destroyed before the canvas can be reused." while **rebinding** the chart from API,

    We are getting an error "ERROR Error: Canvas is already in use. Chart with ID '2' must be destroyed before the canvas can be reused." while rebinding the chart from API,

    we have used
    ctx.clear(); and ctx.destroy() method for clearing the canvas but getting errors while used ERROR TypeError: ctx.destroy is not a functin

    ERROR Error: Canvas is already in use. Chart with ID '2' must be destroyed before the canvas can be reused. at new Chart (chart.esm.js:5354:1) at new WordCloudChart (index.umd.js:747:1) at EmployeeComponent.wordcloudChart (employee.component.ts:281:21) at employee.component.ts:339:14 at Object.next (Subscriber.js:110:1) at SafeSubscriber._next (Subscriber.js:60:1) at SafeSubscriber.next (Subscriber.js:31:1) at map.js:7:1 at OperatorSubscriber._next (OperatorSubscriber.js:9:1) at OperatorSubscriber.next (Subscriber.js:31:1)

    question wontfix 
    opened by VikasSaxenaxcdify 1
  • WordCloud and Venn Charts in ChartJs 2.9.X versions or 2.X versions?

    WordCloud and Venn Charts in ChartJs 2.9.X versions or 2.X versions?

    I am great fan of your work. My question, is there a way to make Venn and WordCloud plugins work in 2.X versions of Chart.Js. Preferably last stable version 2.9.4 of Chart.Js 2?

    question answered 
    opened by skowsikaxl 1
Releases(v4.1.0)
Owner
Samuel Gratzl
Research Software Engineer with a focus on Data Visualization - author of @lineupjs and @upsetjs
Samuel Gratzl
This plugin for Chart.js that makes your bar chart to 100% stacked bar chart.

chartjs-plugin-stacked100 This plugin for Chart.js that makes your bar chart to 100% stacked bar chart. Requires Chart.js 3.x. Demo: https://y-takey.g

y-take 106 Jan 3, 2023
A Simple Dashboard Chart in Laravel Nova using Chart JS

A Simple Dashboard Chart in Laravel Nova using Chart JS. Starting create your own dashboard with Chart JS Integration can save your time and help you maintain consistency across standard elements such as Bar, Stacked, Line, Area, Doughnut and Pie Chart.

Kuncoro Wicaksono 177 Jan 4, 2023
Chart.js plugin to defer initial chart updates

Chart.js plugin to defer initial chart updates until the user scrolls and the canvas appears inside the viewport, and thus trigger the initial chart a

Chart.js 97 Nov 9, 2022
Bar Funnel Chart extension for Chart.js

Chart.BarFunnel.js Provides a Bar Funnel Chart for use with Chart.js Documentation To create a Bar Funnel Chart, include Chart.BarFunnel.js after Char

Chart.js 58 Nov 24, 2022
TradeX-chart is a trade chart written in plain (vanilla) JavaScript with minimal dependencies

TradeX-chart is a trade chart written in plain (vanilla) JavaScript with minimal dependencies; use it with any framework or backend.

null 24 Dec 12, 2022
Redefined chart library built with React and D3

Recharts Introduction Recharts is a Redefined chart library built with React and D3. The main purpose of this library is to help you to write charts i

recharts 19.4k Jan 2, 2023
:bar_chart: A D3-based reusable chart library

c3 c3 is a D3-based reusable chart library that enables deeper integration of charts into web applications. Follow the link for more information: http

C3.js 9.2k Jan 2, 2023
GPL version of Javascript Gantt Chart

dhtmlxGantt Getting started | Features | Follow us | License | Useful links dhtmlxGantt is an open source JavaScript Gantt chart that helps you illust

null 952 Dec 29, 2022
🍞📊 Beautiful chart for data visualization.

?? ?? Spread your data on TOAST UI Chart. TOAST UI Chart is Beautiful Statistical Data Visualization library. ?? Packages The functionality of TOAST U

NHN 5.2k Jan 2, 2023
:bar_chart: Re-usable, easy interface JavaScript chart library based on D3.js

billboard.js is a re-usable, easy interface JavaScript chart library, based on D3 v4+. The name "billboard" comes from the famous billboard chart whic

NAVER 5.4k Jan 1, 2023
:bar_chart: A library of modular chart components built on D3

Plottable Plottable is a library of chart components for creating flexible, custom charts for websites. It is built on top of D3.js and provides highe

Palantir Technologies 2.9k Dec 31, 2022
Chart image and QR code web API

QuickChart QuickChart is a service that generates images of charts from a URL. Because these charts are simple images, they are very easy to embed in

Ian Webster 1.3k Dec 25, 2022
📈 A small, fast chart for time series, lines, areas, ohlc & bars

?? μPlot A small (~35 KB min), fast chart for time series, lines, areas, ohlc & bars (MIT Licensed) Introduction μPlot is a fast, memory-efficient Can

Leon Sorokin 7.5k Jan 7, 2023
TChart.js - simple and configurable Bar and Line Chart library in Javascript

TChart.js Simple and configurable Bar and Line Chart library in Javascript Description TChart.js is a canvas-based simple Javascript Bar and Line Char

null 4 Mar 3, 2021
🍞📊 Beautiful chart for data visualization.

?? ?? Spread your data on TOAST UI Chart. TOAST UI Chart is Beautiful Statistical Data Visualization library. ?? Packages The functionality of TOAST U

NHN 5.2k Jan 6, 2023
The power of Chart.js in Jupyter !

The power of Chart.js in Jupyter Notebooks Installation You can install ipychart from your terminal using pip or conda: # using pip $ pip install ipyc

Nicolas H 68 Dec 8, 2022
Chart.js bindings for OCaml

chartjs-ocaml: OCaml bindings for Chart.js This library provides OCaml bindings for the Chart.js charting library and some popular plugins. Following

Alex Yanin 13 Aug 20, 2022
Java library for use with Chart.js javascript library

Chart.java Chart.java enables integration with the excellent Chart.js library from within a Java application. Usage example In Java: BarDataset datase

Marceau Dewilde 102 Dec 16, 2022
J2CL and GWT Charts library based on CHART.JS

Charba - J2CL and GWT Charts library based on CHART.JS What's Charba GWT Web toolkit doesn't have charting library available out of the box. There are

Pepstock.org 56 Dec 17, 2022