Skip to content

Instantly share code, notes, and snippets.

@msrivastav13
Created June 14, 2019 23:24
Show Gist options
  • Save msrivastav13/66d58042063ae26d6f74d90a582089b2 to your computer and use it in GitHub Desktop.
Save msrivastav13/66d58042063ae26d6f74d90a582089b2 to your computer and use it in GitHub Desktop.
wordcloud lwc demo
<template>
<lightning-card title="Word Cloud Demo">
<canvas class="my_canvas" lwc:dom="manual"></canvas>
</lightning-card>
</template>
import { LightningElement } from 'lwc';
import {loadScript} from 'lightning/platformResourceLoader';
import wordcloud from '@salesforce/resourceUrl/wordcloud2';
export default class Wordcloud extends LightningElement {
list = [['foo', 12], ['bar', 6], ['foo', 20], ['bar', 18]];
renderedCallback() {
if (this.cloudInit) {
return;
}
this.cloudInit = true;
loadScript(this, wordcloud)
.then(() => {
this.initializeWordCloud();
})
.catch(error => {
// eslint-disable-next-line no-console
console.log(error);
});
}
initializeWordCloud(){
window.WordCloud(this.template.querySelector('canvas.my_canvas'), {
list: this.list
});
}
}
<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>46.0</apiVersion>
<isExposed>true</isExposed>
<description>A LWC Bundle</description>
<masterLabel>wordcloud</masterLabel>
<targets>
<target>lightning__HomePage</target>
</targets>
</LightningComponentBundle>
@msrivastav13
Copy link
Author

@ksukhija1
Copy link

@msrivastav I am trying to built word cloud , on which i am storing values from different fields from different objects and storing them in a list and than displaying on word cloud , But it is not happening. Please help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment