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 data set on our data
3
var dataSet = anychart.data.set([
4
['Lip gloss', 22998, 12043],
5
['Eyeliner', 12321, 15067],
6
['Eyeshadows', 12998, 12043],
7
['Powder', 10261, 14419],
8
['Mascara', 11261, 10419],
9
['Foundation', 10342, 10119],
10
['Rouge', 11624, 7004],
11
['Lipstick', 8814, 9054],
12
['Eyebrow pencil', 11012, 5067],
13
['Nail polish', 9814, 3054]
14
]);
15
16
// map data for the first series, take x from the zero column and value from the first column of data set
17
var firstSeriesData = dataSet.mapAs({ x: 0, value: 1 });
18
19
// map data for the second series, take x from the zero column and value from the second column of data set
20
var secondSeriesData = dataSet.mapAs({ x: 0, value: 2 });
21
22
// create column chart
23
var chart = anychart.column();
24
25
// turn on chart animation
26
chart.animation(true);
27
28
// set chart title text settings
29
chart.title('Top 10 Products by Revenue in two Regions');
30
31
// temp variable to store series instance
32
var series;
33
34
// helper function to setup label settings for all series
35
var setupSeries = function (series, name) {
36
series.name(name);
37
series.selected().fill('#f48fb1 0.8').stroke('1.5 #c2185b');
38
};
39
40
// create first series with mapped data
41
series = chart.column(firstSeriesData);
42
series.xPointPosition(0.45);
43
setupSeries(series, 'Florida');
44
45
// create second series with mapped data
46
series = chart.column(secondSeriesData);
47
series.xPointPosition(0.25);
48
setupSeries(series, 'Texas');
49
50
// set chart padding
51
chart.barGroupsPadding(0.3);
52
53
// format numbers in y axis label to match browser locale
54
chart.yAxis().labels().format('${%Value}{groupsSeparator: }');
55
56
// set titles for Y-axis
57
chart.yAxis().title('Revenue in Dollars');
58
59
// turn on legend
60
chart.legend().enabled(true).fontSize(13).padding([0, 0, 20, 0]);
61
62
chart.interactivity().hoverMode('single');
63
64
chart.tooltip().format('${%Value}{groupsSeparator: }');
65
66
// set container id for the chart
67
chart.container('container');
68
69
// initiate chart drawing
70
chart.draw();
71
});