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
var data = [
3
['Eyebrow pencil', 5221],
4
['Nail polish', 9256],
5
['Lipstick', 3308],
6
['Lip gloss', 5432],
7
['Mascara', 13701],
8
['Foundation', 4008],
9
['Eyeshadows', 4229],
10
['Rouge', 18712],
11
['Powder', 10419],
12
['Eyeliner', 3932]
13
];
14
15
// sort data by alphabet order
16
data.sort(function (itemFirst, itemSecond) {
17
return itemSecond[1] - itemFirst[1];
18
});
19
20
// create bar chart
21
var chart = anychart.bar();
22
23
// turn on chart animation
24
chart
25
.animation(true)
26
.padding([10, 40, 5, 20])
27
// set chart title text settings
28
.title('Top 10 Cosmetic Products by Revenue');
29
30
// create area series with passed data
31
var series = chart.bar(data);
32
// set tooltip formatter
33
series
34
.tooltip()
35
.position('right')
36
.anchor('left-center')
37
.offsetX(5)
38
.offsetY(0)
39
.format('${%Value}{groupsSeparator: }');
40
41
// set titles for axises
42
chart.xAxis().title('Products by Revenue');
43
chart.yAxis().title('Revenue in Dollars');
44
chart.interactivity().hoverMode('by-x');
45
chart.tooltip().positionMode('point');
46
// set scale minimum
47
chart.yScale().minimum(0);
48
49
// set container id for the chart
50
chart.container('container');
51
// initiate chart drawing
52
chart.draw();
53
});