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
['Powder', 10261, 14419, 5134, 25712]
14
]);
15
16
// map data for the first series, take x from the zero area and value from the first area 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 area and value from the second area of data set
20
var secondSeriesData = dataSet.mapAs({ x: 0, value: 2 });
21
22
// map data for the second series, take x from the zero area and value from the third area of data set
23
var thirdSeriesData = dataSet.mapAs({ x: 0, value: 3 });
24
25
// map data for the fourth series, take x from the zero area and value from the fourth area of data set
26
var fourthSeriesData = dataSet.mapAs({ x: 0, value: 4 });
27
28
// create bar chart
29
var chart = anychart.area3d();
30
31
// turn on chart animation
32
chart.animation(true);
33
34
// turn on the crosshair
35
var crosshair = chart.crosshair();
36
crosshair.enabled(true).yStroke(null).xStroke('#fff').zIndex(39);
37
crosshair.yLabel().enabled(false);
38
39
// force chart to stack values by Y scale.
40
chart.yScale().stackMode('value');
41
42
// set chart title text settings
43
chart.title('Top 10 Products by Revenue from Different Regions');
44
chart.title().padding([0, 0, 5, 0]);
45
46
// helper function to setup label settings for all series
47
var setupSeriesLabels = function (series, name) {
48
series.name(name);
49
series.stroke('3 #fff 1');
50
series.hovered().stroke('3 #fff 1');
51
series
52
.hovered()
53
.markers()
54
.enabled(true)
55
.type('circle')
56
.size(4)
57
.stroke('1.5 #fff');
58
};
59
60
// temp variable to store series instance
61
var series;
62
63
// create first series with mapped data
64
series = chart.area(firstSeriesData);
65
setupSeriesLabels(series, 'Florida');
66
67
// create second series with mapped data
68
series = chart.area(secondSeriesData);
69
setupSeriesLabels(series, 'Texas');
70
71
// create third series with mapped data
72
series = chart.area(thirdSeriesData);
73
setupSeriesLabels(series, 'Arizona');
74
75
// create fourth series with mapped data
76
series = chart.area(fourthSeriesData);
77
setupSeriesLabels(series, 'Nevada');
78
79
// turn on legend
80
chart.legend().enabled(true).fontSize(13).padding([0, 0, 20, 0]);
81
// set yAxis labels formatter
82
chart.yAxis().labels().format('{%Value}{groupsSeparator: }');
83
84
// set titles for axises
85
chart.xAxis().title('Products by Revenue');
86
chart.yAxis().title('Revenue in Dollars');
87
chart.interactivity().hoverMode('by-x');
88
89
// set tooltip settings
90
chart.tooltip().displayMode('union').valuePrefix('$');
91
92
// set container id for the chart
93
chart.container('container');
94
95
// initiate chart drawing
96
chart.draw();
97
});