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
{name: "Total Market", value: 232000, custom_field: "info 1"},
6
{name: "Prospects", value: 94480, custom_field: "info 2"},
7
{name: "Leads", value: 47390, custom_field: "info 3"},
8
{name: "Sales", value: 22181, custom_field: "info 4"}
9
];
10
11
// create a chart and set the data
12
var chart = anychart.funnel(data);
13
14
// enable HTML for labels and tooltips
15
chart.labels().useHtml(true);
16
chart.tooltip().useHtml(true);
17
18
// configure labels
19
chart.labels().format(function() {
20
var percentOfTotal = (this.getData("value")*100)/this.getStat("sum");
21
if (percentOfTotal > 50)
22
return "<span style='color:#dd2c00;font-weight:bold'>" +
23
this.x + ": " + percentOfTotal.toFixed(1) + "%</span>";
24
return this.x + ": " + percentOfTotal.toFixed(1) + "%";
25
});
26
27
// configure tooltips
28
chart.tooltip().format(function() {
29
var percentOfTotal = (this.getData("value")*100)/this.getStat("sum");
30
if (percentOfTotal > 50)
31
return "<span style='font-size:18'>" +
32
percentOfTotal.toFixed(1) + "% (" +
33
this.value + ")</span><br><br>" +
34
this.getData("custom_field");
35
return percentOfTotal.toFixed(1) + "% (" + this.value +
36
")<br><br>" + this.getData("custom_field");
37
});
38
39
// set the container id
40
chart.container("container");
41
42
// initiate drawing the chart
43
chart.draw();
44
});