HTMLcopy
1
<div id="container1"></div>
2
<div id="container2"></div>
3
<div id="container3"></div>
CSScopy
x
1
html, body {
2
width: 100%;
3
height: 100%;
4
margin: 0;
5
padding: 0;
6
}
7
8
#container1 {
9
/* border: 1px solid blue; */
10
width: 65%;
11
height: 100%;
12
float:left;
13
/*float: left;*/
14
/*width: 600px;*/
15
/*height: 400px;*/
16
/*margin-left: 50px;*/
17
/*margin-top: 30px;*/
18
}
19
20
#container2 {
21
/* border: 1px solid blue; */
22
width: 30%;
23
height: 50%;
24
display: inline-block;
25
float: left;
26
/*width: 600px;*/
27
/*height: 400px;*/
28
/*margin-left: 50px;*/
29
/*margin-top: 30px;*/
30
}
31
32
#container3 {
33
/* border: 1px solid blue; */
34
width: 30%;
35
height: 50%;
36
float: left;
37
/*width: 600px;*/
38
/*height: 400px;*/
39
/*margin-left: 50px;*/
40
/*margin-top: 30px;*/
41
}
JavaScriptcopy
195
1
2
var area;
3
var pie;
4
var circlePacking;
5
6
var dataSet = anychart.data.set([
7
['Jan 2022', 1000, 0, 1200, 500],
8
['Feb 2022', 800, 0, 1100, 700],
9
['Mar 2022', 850, 250, 1300, 1100],
10
['Apr 2022', 1100, 450, 900, 750],
11
['May 2022', 1300, 650, 550, 0],
12
['Jun 2022', 720, 350, 150, 650],
13
['Jul 2022', 950, 0, 0, 850],
14
['Aug 2022', 1050, 800, 0, 1400],
15
['Sep 2022', 1250, 640, 0, 900],
16
['Oct 2022', 1100, 370, 450, 150],
17
['Nov 2022', 1050, 350, 0, 0],
18
['Dec 2022', 900, 170, 0, 100],
19
]);
20
21
function createArea() {
22
// map data for the first series, take x from the zero area and value from the first area of data set
23
var seriesData_1 = dataSet.mapAs({ 'x': 0, 'value': 1 });
24
25
// map data for the second series, take x from the zero area and value from the second area of data set
26
var seriesData_2 = dataSet.mapAs({ 'x': 0, 'value': 2 });
27
28
// map data for the second series, take x from the zero area and value from the third area of data set
29
var seriesData_3 = dataSet.mapAs({ 'x': 0, 'value': 3 });
30
31
// map data for the fourth series, take x from the zero area and value from the fourth area of data set
32
var seriesData_4 = dataSet.mapAs({ 'x': 0, 'value': 4 });
33
34
// map data for the fifth series, take x from the zero area and value from the fourth area of data set
35
var seriesData_5 = dataSet.mapAs({ 'x': 0, 'value': 5 });
36
37
// create bar chart
38
area = anychart.area();
39
40
var crosshair = area.crosshair();
41
crosshair.enabled(true).yStroke(null).xStroke('#fff').zIndex(39);
42
crosshair.yLabel().enabled(false);
43
44
area.yScale().stackMode('value');
45
46
// set chart title text settings
47
area.title('Financial expenses');
48
49
// helper function to setup label settings for all series
50
function setupSeriesLabels(series, name) {
51
series.name(name)
52
.stroke('3 #fff 1')
53
.fill(function () {
54
return this.sourceColor + ' 0.8'
55
});
56
series.hovered().stroke('3 #fff 1');
57
series.hovered().markers()
58
.enabled(true)
59
.type('circle')
60
.size(4)
61
.stroke('1.5 #fff');
62
series.markers().zIndex(100);
63
};
64
65
var series1 = area.splineArea(seriesData_1);
66
setupSeriesLabels(series1, 'QLIK Prortal');
67
68
// create second series with mapped data
69
var series2 = area.splineArea(seriesData_2);
70
setupSeriesLabels(series2, 'Circular gauge');
71
72
// create third series with mapped data
73
var series3 = area.splineArea(seriesData_3);
74
setupSeriesLabels(series3, 'Decomosition tree');
75
76
// create fourth series with mapped data
77
var series4 = area.splineArea(seriesData_4);
78
setupSeriesLabels(series4, 'Combo Chart');
79
80
// turn on legend
81
area.legend().enabled(true);
82
83
// set titles for axises
84
area.xAxis().title(false);
85
area.xAxis().orientation('top');
86
87
area.yAxis().title('Monthly bablo spent, $');
88
89
// enable grids
90
area.yGrid().stroke('#ddd');
91
area.xGrid().stroke('#ddd');
92
93
area.tooltip().titleFormat(function () {
94
const total = this.points.reduce((acc, curr) => {
95
return acc + curr.value;
96
}, 0)
97
return `${this.x}, sum: ${total}$`;
98
});
99
100
// interactivity and tooltip settings
101
area.interactivity().hoverMode('by-x');
102
103
// set container id for the chart
104
area.container('container1');
105
106
// initiate chart drawing
107
area.draw();
108
109
area.yAxis().scale().inverted(true);
110
111
area.listen('pointmousemove', e => {
112
const { pointIndex } = e;
113
114
// console.log(e);
115
116
var seriesList = [];
117
for (var i = 0; i < area.getSeriesCount(); i++) {
118
seriesList.push(area.getSeriesAt(i));
119
}
120
121
var x = '';
122
const points = seriesList.map(series => {
123
const point = series.getPoint(pointIndex);
124
x = point.get('x');
125
return point.get('value');
126
});
127
128
// console.log(points);
129
130
var pieData = points.map((val, index) => {
131
return {
132
x: area.getSeriesAt(index).name(),
133
value: val || 0.001
134
}
135
});
136
pie.title(x);
137
pie.data(pieData);
138
139
var cpData = points.map((val, index) => {
140
return {
141
name: area.getSeriesAt(index).name(),
142
value: val || 0.001
143
}
144
});
145
circlePacking.data(cpData, 'as-tree');
146
})
147
}
148
149
function createPie() {
150
pie = anychart.pie([
151
{ x: 'QLIK Prortal', value: 1000 },
152
{ x: 'Circular gauge', value: 0 },
153
{ x: 'Decomposition tree', value: 1200 },
154
{ x: 'Combo chart', value: 500 },
155
]);
156
157
pie.labels()
158
.format('{%X}\n{%PercentValue}{decimalsCount:1,zeroFillDecimals:true}%')
159
.fontSize(8);
160
161
pie.legend(false);
162
pie.title('Jan 2022');
163
pie.container('container2');
164
pie.draw();
165
}
166
167
function createCirclePacking() {
168
// create data
169
var data = [
170
{ name: 'QLIK Prortal', value: 1000 },
171
{ name: 'Circular gauge', value: 0 },
172
{ name: 'Decomposition tree', value: 1200 },
173
{ name: 'Combo chart', value: 500 },
174
];
175
176
// create a chart and set the data
177
circlePacking = anychart.circlePacking(data, 'as-tree');
178
179
// set the container id
180
circlePacking.container("container3");
181
182
circlePacking.labels().enabled(true).fontSize(12).position('center').anchor('center').format(function () {
183
const { name, value } = this;
184
return value > 0.001 ? `${name}\n${value}$` : '';
185
});
186
187
// initiate drawing the chart
188
circlePacking.draw();
189
};
190
191
anychart.onDocumentReady(function () {
192
createArea();
193
createPie();
194
createCirclePacking();
195
});