HTMLcopy
1
<div id="container"></div>
CSScopy
8
1
html,
2
body,
3
#container {
4
width: 100%;
5
height: 100%;
6
margin: 0;
7
padding: 0;
8
}
JavaScriptcopy
x
1
anychart.onDocumentReady(function () {
2
// The data used in this sample can be obtained from the CDN
3
// https://cdn.anychart.com/samples/maps-bubble/bubble-christian-map/data.json
4
anychart.data.loadJsonFile(
5
'https://cdn.anychart.com/samples/maps-bubble/bubble-christian-map/data.json',
6
function (data) {
7
var dataSet = anychart.data.set(data);
8
var mapping = dataSet.mapAs({
9
name: 'name',
10
id: 'id',
11
size: 'amount',
12
value: 'percent'
13
});
14
15
// Creates Map Chart
16
var map = anychart.map();
17
map.padding([20, 0, 10, 0]);
18
// Sets geodata using https://cdn.anychart.com/geodata/latest/custom/world/world.js
19
map.geoData('anychart.maps.world');
20
21
map
22
.credits()
23
.enabled(true)
24
.url('https://en.wikipedia.org/wiki/Christianity_by_country')
25
.text(
26
'Data source: https://en.wikipedia.org/wiki/Christianity_by_country'
27
)
28
.logoSrc('https://en.wikipedia.org/static/favicon/wikipedia.ico');
29
30
// Sets Chart Title
31
map
32
.title()
33
.enabled(true)
34
.text('Christianity in the World by Country')
35
.padding([0, 0, 10, 0]);
36
37
// Sets bubble max size settings
38
map.minBubbleSize('0.5%').maxBubbleSize('5%');
39
40
// Creates bubble series1
41
var series1 = map.bubble(mapping);
42
// Sets series1 settings
43
series1
44
.name('Amount of Christian')
45
// Sets series1 geo id field settings
46
.geoIdField('iso_a2')
47
.fill('#1976d2 0.6')
48
.stroke('1 #1976d2 0.9');
49
series1
50
.legendItem()
51
.iconType('circle')
52
.iconFill('#1976d2 0.6')
53
.iconStroke('1 #1976d2 0.9');
54
55
var series2 = map.choropleth(mapping);
56
series2
57
.name('Percent of Christian')
58
.geoIdField('iso_a2')
59
.legendItem({ iconFill: '#b0bec5' });
60
series2.hovered().fill(series2.fill());
61
series2.colorScale(
62
anychart.scales.linearColor('#f7f7f7', '#b0bec5')
63
);
64
65
map
66
.legend()
67
.enabled(true)
68
.position('center-top')
69
.align('center')
70
.itemsLayout('horizontal')
71
.padding(0, 0, 30, 0)
72
.paginator(false);
73
map.interactivity().selectionMode('none');
74
75
map
76
.tooltip()
77
.useHtml(true)
78
.title({ fontColor: '#7c868e' })
79
.padding([8, 13, 10, 13])
80
.format(function () {
81
var value =
82
'<span style="color: #545f69; font-size: 12px; font-weight: bold">';
83
var description =
84
'<br/><span style="color: #7c868e; font-size: 12px; font-style: italic">';
85
return (
86
value +
87
parseInt(this.getData('amount')).toLocaleString('en-US') +
88
'</span></strong>' +
89
description +
90
this.getData('percent') +
91
'%</span>'
92
);
93
});
94
95
map
96
.tooltip()
97
.background()
98
.enabled(true)
99
.fill('#fff')
100
.stroke('#c1c1c1')
101
.corners(3)
102
.cornerType('round');
103
104
// create zoom controls
105
var zoomController = anychart.ui.zoom();
106
zoomController.render(map);
107
108
// Sets container id for the chart
109
map.container('container');
110
// Initiates chart drawing
111
map.draw();
112
}
113
);
114
});