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
// This sample uses 3rd party proj4 component
4
// that makes it possible to set coordinates
5
// for the points and labels on the map and
6
// required for custom projections and grid labels formatting.
7
// See https://docs.anychart.com/Maps/Map_Projections
8
9
// create stage
10
var stage = anychart.graphics.create("container");
11
map = anychart.map();
12
var dataSet = anychart.data.set([
13
{'id': 'AU.WA', 'value': 300},
14
{'id': 'AU.JB'},
15
{'id': 'AU.NS', 'value': 240},
16
{'id': 'AU.VI', 'value': 75},
17
{'id': 'AU.NT', 'value': 130},
18
{'id': 'AU.TS', 'value': 190},
19
{'id': 'AU.CT'},
20
{'id': 'AU.SA'},
21
{'id': 'AU.QL'}
22
]);
23
24
map.geoData(anychart.maps.australia);
25
26
// set the title and its preferences
27
map.title().useHtml(true).hAlign('center');
28
map.title('<span style="font-size: 18px;">Data Setting</span><br><span style="font-size:12px;">Custom text and image labels on a map</span>');
29
map.padding(10,250,10,0)
30
31
// set the series
32
var series = map.choropleth(dataSet);
33
// enable labels
34
series.labels(true);
35
labels = series.labels();
36
37
// labels setting
38
labels.fontColor('black');
39
labels.fontSize("10px");
40
41
// custom text label
42
custom_label = map.label();
43
custom_label.text("Australia's sons let us rejoice, \nFor we are young and free;\nWe've golden soil and wealth for toil,\nOur home is girt by sea;\nOur land abounds in Nature's gifts\nOf beauty rich and rare;\nIn hist'ry's page, let ev'ry stage\nAdvance Australia fair.\nIn joyful strains then let us sing,\nAdvance Australia fair.");
44
custom_label.position("right-center");
45
custom_label.anchor("right-center");
46
custom_label.offsetX(30);
47
custom_label.width(210);
48
custom_label.fontSize(10);
49
custom_label.fontColor("black");
50
51
// custom image label
52
image = stage.image("https://static.anychart.com/images/australia.png");
53
image.width(150);
54
image.height(150);
55
image.x(stage.width()-225);
56
image.y(stage.height()/2-75);
57
stage.listen("stageresize", function (){
58
image.x(stage.width()-200);
59
image.y(stage.height()/2-50);
60
});
61
image.opacity("0.3");
62
image.zIndex(custom_label.zIndex()+1);
63
64
// set the container
65
map.container(stage);
66
map.draw();
67
});