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/7.14.3/Maps/Map_Projections
8
9
customTheme = {chart: {defaultSeriesSettings: {base: {tooltip: {format:"{%SeriesName}",titleFormat:"{%Name}"}}}}};
10
anychart.theme(customTheme);
11
12
// create map chart
13
var map = anychart.map();
14
// set geodata
15
map.geoData(anychart.maps.united_states_of_america);
16
// name of the chart
17
map.title("American Civil War Map");
18
19
// create data set
20
var data = anychart.data.set([
21
{points: [32, -106.8, 35, -103.5], curvature: -0.27},
22
{points: [35, -103.5, 36.5, -99.5], curvature: 0.47},
23
{points: [36.5, -99.5, 34, -97.3], curvature: 0.25},
24
{points: [34, -97.3, 32.3, -95.27], curvature: -0.3},
25
{points: [32.3,-95.27, 32.9, -92.03], curvature: -0.25},
26
{points: [32.9, -92.03, 40.4, -75.5], curvature: 0.05},
27
{points: [40.4, -75.5, 39.9, -74.1], curvature: 0.45}
28
]);
29
30
// create connector series
31
var series = map.connector(data);
32
33
// set connector series settings
34
series.markers(false);
35
series.color("maroon");
36
series.hoverStroke("maroon", 2);
37
series.name("Hostilities border");
38
series.legendItem().iconType("line");
39
40
// data set for the choropeth series
41
var dataSet_union = anychart.data.set([
42
{id: 'US.MN', name: "Minnesota"},
43
{id: 'US.CA', name: "California"},
44
{id: 'US.NV', name: "Nevada"},
45
{id: 'US.OR', name: "Oregon"},
46
{id: 'US.IA', name: "Iowa"},
47
{id: 'US.KS', name: "Kansas"},
48
{id: 'US.CT', name: "Connecticut"},
49
{id: 'US.MA', name: "Massachusetts"},
50
{id: 'US.NH', name: "New Hampshire"},
51
{id: 'US.RI', name: "Rhode Island"},
52
{id: 'US.VT', name: "Vermont"},
53
{id: 'US.IL', name: "Illinois"},
54
{id: 'US.IN', name: "Indiana"},
55
{id: 'US.OH', name: "Ohio"},
56
{id: 'US.WI', name: "Wisconsin"},
57
{id: 'US.NY', name: "New York"},
58
{id: 'US.PA', name: "Pennsylvania"},
59
{id: 'US.ME', name: "Maine"},
60
{id: 'US.MI', name: "Michigan"}
61
]);
62
63
var dataSet_union_terr_nps = anychart.data.set([
64
{id: 'US.MT', name: "Montana"},
65
{id: 'US.ND', name: "North Dakota"},
66
{id: 'US.ID', name: "Idaho"},
67
{id: 'US.WA', name: "Washington"},
68
{id: 'US.CO', name: "Colorado"},
69
{id: 'US.UT', name: "Utah"},
70
{id: 'US.WY', name: "Wyoming"},
71
{id: 'US.MO', name: "Missouri"},
72
{id: 'US.NE', name: "Nebraska"},
73
{id: 'US.SD', name: "South Dakota"},
74
{id: 'US.WY', name: "Wyoming"}
75
]);
76
77
var dataSet_confederate = anychart.data.set([
78
{id: 'US.AR', name: "Arkansas"},
79
{id: 'US.LA', name: "Louisiana"},
80
{id: 'US.TX', name: "Texas"},
81
{id: 'US.AL', name: "Alabama"},
82
{id: 'US.FL', name: "Florida"},
83
{id: 'US.GA', name: "Georgia"},
84
{id: 'US.MS', name: "Mississippi"},
85
{id: 'US.SC', name: "South Carolina"},
86
{id: 'US.NC', name: "North Carolina"},
87
{id: 'US.TN', name: "Tennessee"},
88
{id: 'US.VA', name: "Virginia"},
89
{id: 'US.DE', name: "Delaware"},
90
{id: 'US.DC', name: "District of Columbia"},
91
{id: 'US.MD', name: "Maryland"},
92
{id: 'US.NJ', name: "New Jersey"}
93
]);
94
95
var dataSet_union_border_states = anychart.data.set([
96
{id: 'US.KY', name: "Kentucky"},
97
{id: 'US.WV', name: "West Virginia"}
98
]);
99
100
var dataSet_union_terr_ps = anychart.data.set([
101
{id: 'US.AZ', name: "Arizona"},
102
{id: 'US.NM', name: "New Mexico"},
103
{id: 'US.OK', name: "Oklahoma"}
104
]);
105
106
// map setting
107
var ch_series_union = map.choropleth(dataSet_union);
108
var ch_series_confederate = map.choropleth(dataSet_confederate);
109
var ch_series_union_terr_nps = map.choropleth(dataSet_union_terr_nps);
110
var ch_series_union_border_states = map.choropleth(dataSet_union_border_states);
111
var ch_series_union_terr_ps = map.choropleth(dataSet_union_terr_ps);
112
113
// names for the series a
114
ch_series_union.name("Union");
115
ch_series_confederate.name("Confederation");
116
ch_series_union_terr_nps.name("Union territories (no slavery)");
117
ch_series_union_border_states.name("Border Union states (slavery)");
118
ch_series_union_terr_ps.name("Union territories claimed by Confederacy (slavery)");
119
120
// setting the colors
121
ch_series_union.color("#0288d1");
122
ch_series_union_terr_nps.color("#40c4ff");
123
ch_series_confederate.color("#8d5932");
124
ch_series_union_border_states.color("#d8b597");
125
ch_series_union_terr_ps.color("#f2d1be");
126
ch_series_union_terr_nps.color("#6666FF");
127
128
// disabling the states that were not part of USA at the time of the Civil War
129
map.unboundRegions(false);
130
131
// legend
132
map.legend(true);
133
map.legend().position("bottom");
134
135
// set container id for the chart
136
map.container('container');
137
// initiate chart drawing
138
map.draw();
139
});