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
var data = [
10
{'id': 'AU.WA', 'value': 170},
11
{'id': 'AU.NS', 'value': 260},
12
{'id': 'AU.VI', 'value': 75},
13
{'id': 'AU.NT', 'value': 130},
14
{'id': 'AU.TS', 'value': 210},
15
{'id': 'AU.CT'}
16
];
17
18
var map = anychart.map();
19
map.geoData(anychart.maps.australia);
20
21
// stroke the undefined regions
22
map.unboundRegions().stroke('green');
23
24
map.title().useHtml(true).hAlign('center');
25
map.title('<span style="font-size: 18px;">Ordinal Color Scale <br> Single Hue Color Progression');
26
27
// set the colorRange preferences
28
var cr = map.colorRange();
29
cr.colorLineSize(15);
30
cr.align('center');
31
cr.stroke(null);
32
cr.ticks().stroke('rgb(216,216,216)');
33
cr.ticks().position('center').length(15);
34
35
series = map.choropleth(data);
36
series.stroke('#000 .3');
37
series.labels().fontColor('black');
38
39
// define the color of the hovered district
40
series.selected().fill('#5588ff');
41
42
// making of the ordinal colorRange
43
ocs = anychart.scales.ordinalColor([
44
{less: 100},
45
{from: 100, to: 150},
46
{from: 150, to: 200},
47
{from: 200, to: 350},
48
{greater: 250}
49
]);
50
ocs.colors(['rgb(253,225,86)', 'rgb(248,196,57)', 'rgb(244,168,19)', 'rgb(198,109,1)', 'rgb(152,58,0)']);
51
52
// tell the series what to use as a colorRange (colorScale)
53
series.colorScale(ocs);
54
55
map.container('container');
56
map.draw();
57
});