HTMLcopy
1
<script src="https://cdn.anychart.com/releases/8.11.0/js/anychart-core.min.js"></script>
2
<script src="https://cdn.anychart.com/releases/8.11.0/js/anychart-map.min.js"></script>
3
<script src="https://cdn.anychart.com/releases/8.11.0/geodata/countries/united_states_of_america/united_states_of_america.js"></script>
4
<script src="https://cdn.anychart.com/releases/8.11.0/js/anychart-data-adapter.min.js"></script>
5
<script src="https://cdnjs.cloudflare.com/ajax/libs/proj4js/2.3.15/proj4.js"></script>
6
<script src="https://d3js.org/d3.v7.min.js"></script>
7
<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
anychart.data.loadJsonFile(
3
"https://gist.githubusercontent.com/shacheeswadia/eead370d79e0f20df5148b79b6887393/raw/fba29e3dcf1806cab770e845546a136a924cf1d5/dataBubbleMap2.json",
4
function (data) {
5
6
// create a map chart
7
let map = anychart.map();
8
9
// add the u.s. geodata
10
map.geoData("anychart.maps.united_states_of_america");
11
12
// restrict the maximum size of the bubbles
13
map.maxBubbleSize("5%");
14
15
// set a custom coloring pattern
16
let fillColor = d3
17
.scaleQuantile()
18
.domain([20, 50])
19
.range(["#1b8366", "#77dd79", "#f7e975", "#fea43e", "#cf0011"]);
20
data.forEach(function (d) {
21
let diff = d.Petrol - d.PetrolFeb;
22
d.percentRise = ((diff * 100) / d.PetrolFeb).toFixed(2);
23
d.fill = fillColor(d.percentRise);
24
});
25
26
// create a bubble series
27
let series = map
28
.bubble(
29
anychart.data.set(data).mapAs({
30
size: "Petrol"
31
})
32
)
33
.stroke("0");
34
35
// enable and customize the series labels
36
series
37
.labels()
38
.enabled(true)
39
.anchor("left-center")
40
.position("right")
41
.fontColor("#353535")
42
.fontSize(11)
43
.offsetX(5);
44
45
// set the map's title
46
map.title("Gasoline Prices in the United States in July 2022");
47
48
// set the container id
49
map.container("container");
50
51
// initiate the map drawing
52
map.draw();
53
54
}
55
);
56
});
57