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
['Nail polish', 12814, 3054, 4376, 4229],
5
['Eyebrow pencil', 13012, 5067, 3987, 3932],
6
['Rouge', 11624, 7004, 3574, 5221],
7
['Lipstick', 8814, 9054, 4376, 9256],
8
['Eyeshadows', 12998, 12043, 4572, 3308],
9
['Eyeliner', 12321, 15067, 3417, 5432],
10
['Foundation', 10342, 10119, 5231, 13701],
11
['Lip gloss', 22998, 12043, 4572, 4008],
12
['Mascara', 11261, 10419, 6134, 18712]
13
]);
14
15
// map data for the first series, take x from the zero area and value from the first area of data set
16
var firstSeriesData = dataSet.mapAs({ x: 0, value: 1 });
17
18
// map data for the second series, take x from the zero area and value from the second area of data set
19
var secondSeriesData = dataSet.mapAs({ x: 0, value: 2 });
20
21
// map data for the second series, take x from the zero area and value from the third area of data set
22
var thirdSeriesData = dataSet.mapAs({ x: 0, value: 3 });
23
24
// map data for the fourth series, take x from the zero area and value from the fourth area of data set
25
var fourthSeriesData = dataSet.mapAs({ x: 0, value: 4 });
26
27
// create bar chart
28
var chart = anychart.area();
29
30
// turn on chart animation
31
chart.animation(true);
32
33
// force chart to stack values by Y scale.
34
chart.yScale().stackMode('percent');
35
36
var crosshair = chart.crosshair();
37
// turn on the crosshair
38
crosshair.enabled(true).yStroke(null).xStroke('#fff').zIndex(99);
39
crosshair.yLabel().enabled(false);
40
crosshair.xLabel().enabled(false);
41
42
// set chart title text settings
43
chart.title('Regional ratio of cosmetic products sales');
44
chart.title().padding([0, 0, 10, 0]);
45
46
// set yAxis labels formatting, force it to add % to values
47
chart.yAxis(0).labels().format('{%Value}%');
48
49
// helper function to setup label settings for all series
50
var setupSeries = function (series, name) {
51
series
52
.name(name)
53
.stroke('3 #fff 1')
54
.fill(function () {
55
return this.sourceColor + ' 0.8';
56
});
57
series.markers().zIndex(100);
58
series.hovered().stroke('3 #fff 1');
59
series
60
.hovered()
61
.markers()
62
.enabled(true)
63
.type('circle')
64
.size(4)
65
.stroke('1.5 #fff');
66
};
67
68
// temp variable to store series instance
69
var series;
70
71
// create first series with mapped data
72
series = chart.area(firstSeriesData);
73
setupSeries(series, 'USA');
74
75
// create second series with mapped data
76
series = chart.area(secondSeriesData);
77
setupSeries(series, 'China');
78
79
// create third series with mapped data
80
series = chart.area(thirdSeriesData);
81
setupSeries(series, 'EU');
82
83
// create fourth series with mapped data
84
series = chart.area(fourthSeriesData);
85
setupSeries(series, 'Africa');
86
87
// set interactivity and toolitp settings
88
chart.interactivity().hoverMode('by-x');
89
chart.tooltip().displayMode('union');
90
91
// turn on legend
92
chart.legend().enabled(true).fontSize(13).padding([0, 0, 25, 0]);
93
94
// set container id for the chart
95
chart.container('container');
96
97
// initiate chart drawing
98
chart.draw();
99
});