HTMLcopy
1
<div class="controls">
2
<label id="label" for="input">Enter up to two words to search them in Donald Trump's twitter:</label>
3
<input id="input" type="text">
4
</div>
5
<div id="container"></div>
CSScopy
x
1
html,
2
body,
3
#container {
4
width: 100%;
5
height: 100%;
6
margin: 0;
7
padding: 0;
8
}
9
10
#container {
11
height: calc(100% - 2em);
12
}
13
14
.controls {
15
text-align: center;
16
}
17
18
#label {
19
font-size: 1em;
20
}
21
22
#input {
23
width: auto;
24
font-size: 1.8em;
25
border: none;
26
box-shadow: none;
27
padding: 0 15px;
28
border-bottom: 2px solid #456;
29
}
JavaScriptcopy
66
1
var preloader = anychart.ui.preloader();
2
preloader.render(document.getElementById('container'));
3
4
// show preloader
5
preloader.visible(true);
6
anychart.onDocumentReady(function () {
7
anychart.data.loadJsonFile(
8
// The data used in this sample can be obtained from the CDN
9
'https://cdn.anychart.com/samples-data/word-tree/trump-tweets/tweets.json',
10
function (data) {
11
// create word-tree chart
12
var chart = anychart.wordtree(data);
13
14
// disable chart tooltip
15
chart.tooltip(false);
16
17
// set chart's font size minimum and maximum
18
chart.minFontSize(3);
19
chart.maxFontSize(20);
20
21
// set chart connectors settings
22
chart.connectors().length(50).offset(5).stroke('#1AA1F1');
23
24
// set the root word
25
chart.word('Fake');
26
27
// drill down to the next word in the tree
28
chart.drillTo('News');
29
30
// set container id for the chart
31
chart.container('container');
32
33
// initiate chart drawing
34
chart.draw();
35
36
// hide preloader
37
preloader.visible(false);
38
39
// listener for input
40
document
41
.getElementById('input')
42
.addEventListener('change', function (e) {
43
// get array of words from input
44
var words = e.target.value.split(' ');
45
// Set visible preloader
46
if (words.length > 1) {
47
// set first word from the input as root of the tree
48
chart.word(words[0]);
49
50
// drill down tree to the last word from the input
51
try {
52
chart.drillTo(words[words.length - 1]);
53
} catch (err) {
54
return false;
55
}
56
} else {
57
// set word from the input as root of the tree
58
chart.word(e.target.value);
59
}
60
});
61
62
document.getElementById('input').value = 'Fake News';
63
document.getElementById('input').focus();
64
}
65
);
66
});