Google Word Trees in Salesforce


A word tree depicts multiple parallel sequences of words. It could be used to show which words most often follow or precede a target word (e.g., "Cats are...") or to show a hierarchy of terms (e.g., a decision tree).

Google word trees are able to process large amounts of text quickly. Modern systems should be able to handle novel-sized amounts of text without significant delay. Word trees are rendered in the browser using SVG, which means it will work in all modern browsers (e.g., Chrome, Firefox, Opera, and Internet Explorer 9+). Like all Google charts, word trees display tooltips when the user hovers over the data.

Visualforce
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<apex:page controller="Vlog_wordTreeCtrl" >
    <apex:form >
        <html>
            <head>
                <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js">
                </script>
             	<script type="text/javascript">
                    google.charts.load('current', {'packages':['wordtree']});
                google.charts.setOnLoadCallback(drawChart);
                
                var Name = '{!Name}';
                Name = Name.replace("[","");
                Name = Name.replace("]","");
                var NameArr=Name.split(',');
                
                function drawChart() {
                    
                    var data = new google.visualization.DataTable();
                    data.addColumn('string', 'Phrases');
                    for (var i = 0; i < NameArr.length; i++) {
                        data.addRow([NameArr[i]]);
                    } 
                    
                    var options = {
                        wordtree: {
                            format: 'implicit',
                            word: 'cats'
                        }
                    };
                    
                    var chart = new google.visualization.WordTree(document.getElementById('chart_div'));
                    
                    chart.draw(data, options);
                }
                </script>
            </head>
            <body>
                
                <div id="chart_div"></div>
            </body>
        </html>
    </apex:form>
</apex:page>


Apex
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
public class Vlog_wordTreeCtrl {
    public List<String> Name{get;set;}
    public List<wordTreeData__c> wtList;
    public Vlog_wordTreeCtrl(){
         Name = new List<String>();
        wtList = [SELECT Id, Name FROM wordTreeData__c];
        for(wordTreeData__c wt:wtList){
           Name.add(wt.Name);
        }
    }

}


Output



Watch Complete Tutorial below :


 If you have any question please leave a comment below.

If you would like to add something to this post please leave a comment below.
Share this blog with your friends if you find it helpful somehow !

Thanks
Keep Coding 


Post a Comment

0 Comments