HTMLcopy
1
<div id="container"></div>
CSScopy
6
1
html, body, #container {
2
width: 100%;
3
height: 100%;
4
margin: 0;
5
padding: 0;
6
}
JavaScriptcopy
x
1
anychart.onDocumentReady(function () {
2
3
// create data
4
var data = [
5
{x: "learning", value: 80, custom_field: "info 1"},
6
{x: "includes", value: 56, custom_field: "info 2"},
7
{x: "lists", value: 44, custom_field: "info 3"},
8
{x: "meaning", value: 40, custom_field: "info 4"},
9
{x: "useful", value: 36, custom_field: "info 5"},
10
{x: "different", value: 32, custom_field: "info 6"},
11
{x: "grammar", value: 28, custom_field: "info 7"},
12
{x: "teaching", value: 24, custom_field: "info 8"},
13
{x: "example", value: 20, custom_field: "info 9"},
14
{x: "thing", value: 12, custom_field: "info 10"}
15
];
16
17
// create a chart and set the data
18
var chart = anychart.tagCloud(data);
19
20
// enable HTML for tooltips
21
chart.tooltip().useHtml(true);
22
23
// configure tooltips
24
chart.tooltip().format(function() {
25
var percentOfTotal = (this.getData("value")*100)/this.getStat("sum");
26
if (percentOfTotal < 7)
27
return percentOfTotal.toFixed(1) +
28
"%<br><br>" + this.getData("custom_field");
29
if (percentOfTotal > 15)
30
return "<span style='font-size:26'>" +
31
percentOfTotal.toFixed(1) +
32
"%</span><br><br>" +
33
this.getData("custom_field");
34
return "<span style='font-size:18'>" +
35
percentOfTotal.toFixed(1) +
36
"%</span><br><br>" +
37
this.getData("custom_field");
38
});
39
40
// set the chart title
41
chart.title("Tag Cloud Chart: Tooltips (Formatting Functions)");
42
43
// set the container id
44
chart.container("container");
45
46
// initiate drawing the chart
47
chart.draw();
48
});