HTMLcopy
1
<button onclick="getChartById()">Get the chart by id and modify it</button>
2
<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
var stage;
2
anychart.onDocumentReady(function () {
3
stage = anychart.graphics.create('container');
4
5
createChart(anychart.column, 0, 0, '100%', '50%', 'Column chart', 'column');
6
createChart(anychart.line, 0, '50%', '100%', '50%', 'Line chart', 'line');
7
});
8
9
function createChart(type, x, y, width, height, text, id) {
10
var chart = type([
11
{x: 'June', value: 3},
12
{x: 'July', value: 2},
13
{x: 'August', value: 6},
14
{x: 'September', value: 5},
15
{x: 'October', value: 1}
16
]);
17
chart.bounds(x, y, width, height);
18
chart.id(id);
19
chart.title(text);
20
chart.container(stage);
21
chart.draw();
22
}
23
24
function getChartById() {
25
26
// Get the chart by id.
27
var chartById = anychart.getChartById('line');
28
chartById.background('#7fff00 0.2');
29
}