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
// 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
['Pomade', 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 seriesData_1 = 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 seriesData_2 = 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 seriesData_3 = 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 seriesData_4 = dataSet.mapAs({x: [0], value: [4]});
26
27
// create area chart
28
var chart = anychart.area3d();
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
// turn on the crosshair
37
var crosshair = chart.crosshair();
38
crosshair.enabled(true)
39
.yStroke(null)
40
.xStroke('#fff')
41
.zIndex(99);
42
crosshair.yLabel().enabled(false);
43
crosshair.xLabel().enabled(false);
44
45
// set chart title text settings
46
chart.title('Regional ratio of cosmetic products sales');
47
chart.title().padding([0, 0, 10, 0]);
48
49
// set yAxis labels formatting, force it to add % to values
50
chart.yAxis(0).labels().format('{%Value}%');
51
52
// helper function to setup label settings for all series
53
var setupSeries = function (series, name) {
54
series.stroke('3 #fff 1');
55
series.name(name);
56
series.hoverMarkers().enabled(true).type('circle').size(4).stroke('1.5 #fff');
57
series.markers().zIndex(100);
58
series.hoverStroke('3 #fff 1');
59
};
60
61
// temp variable to store series instance
62
var series;
63
64
// create first series with mapped data
65
series = chart.area(seriesData_1);
66
setupSeries(series, 'Florida');
67
68
// create second series with mapped data
69
series = chart.area(seriesData_2);
70
setupSeries(series, 'Texas');
71
72
// create third series with mapped data
73
series = chart.area(seriesData_3);
74
setupSeries(series, 'Arizona');
75
76
// create fourth series with mapped data
77
series = chart.area(seriesData_4);
78
setupSeries(series, 'Nevada');
79
80
// set interactivity and toolitp settings
81
chart.interactivity().hoverMode('byX');
82
chart.tooltip().displayMode('union');
83
84
// turn on legend
85
chart.legend()
86
.enabled(true)
87
.fontSize(13)
88
.padding([0, 0, 25, 0]);
89
90
// set container id for the chart
91
chart.container('container');
92
93
// initiate chart drawing
94
chart.draw();
95
});