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