HTMLcopy
1
<button onclick="renderAsync()">Render 80 Charts Async</button>
2
<button onclick="renderSync()">Render 80 Charts Sync</button>
3
<div id="container"></div>
CSScopy
15
1
html, body {
2
width: 100%;
3
height: 100%;
4
margin: 0;
5
padding: 0;
6
}
7
button {
8
margin: 10px 0 0 10px;
9
}
10
#container {
11
position: absolute;
12
width: 100%;
13
top: 35px;
14
bottom: 0;
15
}
JavaScriptcopy
x
1
anychart.onDocumentReady(function () {
2
stage = anychart.graphics.create("container");
3
4
var customTitle = anychart.standalones.title();
5
customTitle.text("Asynchronous/Synchronous Rendering");
6
customTitle.parentBounds(0, "50%", 100, 100);
7
customTitle.container(stage);
8
customTitle.draw();
9
10
charts = [];
11
});
12
13
function renderAsync() {
14
disposeCharts(charts);
15
16
// Set rendering mode to async.
17
createCharts(charts, true);
18
}
19
20
function renderSync() {
21
disposeCharts(charts);
22
23
// Set rendering mode to sync.
24
createCharts(charts, false);
25
}
26
27
function createCharts(charts, sync) {
28
for (var i = 0; i < 15; i++) {
29
for (var j = 2; j < 15; j++) {
30
pieChart = anychart.pie([
31
Math.random(),
32
Math.random(),
33
Math.random()
34
]);
35
pieChart.bounds(i * 10 + "%", j * 10 + "%", "10%", "10%");
36
pieChart.labels(false);
37
pieChart.legend(false);
38
pieChart.padding(0);
39
pieChart.margin(0);
40
pieChart.container(stage);
41
42
/* Set render mode:
43
true - async, false (default) - sync*/
44
pieChart.draw(sync);
45
charts.push(pieChart);
46
}
47
}
48
}
49
50
function disposeCharts(charts) {
51
for (var i = 0; i < charts.length; i++) {
52
charts[i].dispose();
53
}
54
}