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
// create bar chart
3
var chart = anychart.bar();
4
5
// turn on chart animation
6
chart
7
.animation(true)
8
// set chart title text settings
9
.title('World\'s largest cities');
10
11
chart
12
.credits()
13
.enabled(true)
14
.url(
15
'https://en.wikipedia.org/wiki/List_of_cities_proper_by_population'
16
)
17
.text(
18
'Data source: https://en.wikipedia.org/wiki/List_of_cities_proper_by_population'
19
)
20
.logoSrc('https://en.wikipedia.org/static/favicon/wikipedia.ico');
21
22
// create stick series with passed data
23
chart.stick(getData());
24
25
// set scale minimum
26
chart.yScale().minimum(0).ticks().interval(5);
27
// tooltips position and interactivity settings
28
chart
29
.tooltip()
30
.positionMode('point')
31
// set series tooltip settings
32
.format(function () {
33
return (
34
'Population in 2016: ' +
35
anychart.format.number(this.value, { groupsSeparator: ' ' }) +
36
' mln'
37
);
38
});
39
40
chart.interactivity().hoverMode('by-x');
41
// axes titles
42
chart.yAxis().title('Population (millions)');
43
// set container id for the chart
44
chart.container('container');
45
// initiate chart drawing
46
chart.draw();
47
});
48
49
function getData() {
50
return [
51
['Shanghai', 24.2],
52
['Karachi', 23.5],
53
['Beijing', 21.5],
54
['Delhi', 16.7],
55
['Lagos', 16.0],
56
['Tianjin', 15.2],
57
['Istanbul', 14.1],
58
['Tokyo', 13.5],
59
['Guangzhou', 13],
60
['Mumbai', 12.4],
61
['Moscow', 12.1],
62
['São Paulo', 11.8],
63
['Shenzhen', 10.4],
64
['Jakarta', 10.1],
65
['Lahore', 10],
66
['Seoul', 9.9],
67
['Wuhan', 9.7],
68
['Kinshasa', 9.7],
69
['Cairo', 9.2],
70
['Mexico City', 8.8]
71
];
72
}