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-choropleth/dealership-locator/data.json
4
anychart.data.loadJsonFile(
5
'https://cdn.anychart.com/samples/maps-choropleth/dealership-locator/data.json',
6
function (data) {
7
var baseLink = 'https://en.wikipedia.org/wiki/';
8
// create map chart
9
var map = anychart.map();
10
// The data used in this sample can be obtained from the CDN
11
// https://cdn.anychart.com/samples/maps-choropleth/dealership-locator/data.js
12
var dealershipData = data;
13
14
// settings for map chart
15
map
16
.padding([10, 0, 10, 10])
17
.geoData('anychart.maps.united_states_of_america')
18
.interactivity({ selectionMode: 'none' });
19
20
map
21
.title()
22
.enabled(true)
23
.useHtml(true)
24
.padding([10, 0, 10, 0])
25
.text(
26
'ACME Dealership Locator by State<br/>' +
27
'<span style="color:#929292; font-size: 12px;">' +
28
'(Numbers on map - amount of ACME dealerships for each state)</span>'
29
);
30
31
// create choropleth series for map chart
32
var mapSeries = map.choropleth(anychart.data.set(dealershipData));
33
mapSeries
34
.geoIdField('code_hasc')
35
.colorScale(
36
anychart.scales.linearColor('#f2f2f2', '#42a5f5', '#1976d2')
37
);
38
39
mapSeries
40
.hovered()
41
.fill(mapSeries.fill())
42
.stroke(mapSeries.stroke());
43
44
// custom text in tooltips for choropleth series for map chart
45
mapSeries
46
.tooltip()
47
.useHtml(true)
48
.titleFormat('{%Id}')
49
.format(function () {
50
var amount =
51
'<span style="color: #d9d9d9;">ACME has no dealerships in ' +
52
this.getData('name');
53
if (this.value > 0 && this.value === 1) {
54
amount =
55
'<span style="color: #d9d9d9;">' +
56
'ACME has <strong><span style="color: #fff;">' +
57
this.value +
58
' </span></strong>dealership in ' +
59
this.getData('name') +
60
'</span><br/>Click to see more.';
61
} else if (this.value > 1) {
62
amount =
63
'<span style="color: #d9d9d9;">' +
64
'ACME has <strong><span style="color: #fff;">' +
65
this.value +
66
' </span></strong>dealerships in ' +
67
this.getData('name') +
68
'</span><br/>Click to see more.';
69
}
70
return amount;
71
});
72
73
// onclick function for points - redirecting client (based on baseLink variable)
74
map.listen('pointClick', function (e) {
75
window.open(
76
baseLink + dealershipData[e.pointIndex].name,
77
'_blank'
78
);
79
});
80
81
// set container id for the chart
82
map.container('container');
83
// initiate chart drawing
84
map.draw();
85
}
86
);
87
});