HTMLcopy
1
<button onclick="addPoint()">Append Point</button>
2
<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
3
// data
4
data = anychart.data.set([
5
{x: "P1", value: 10},
6
{x: "P2", value: 2},
7
{x: "P3", value: 15},
8
{x: "P4", value: 10},
9
{x: "P5", value: 15}
10
]);
11
12
// set chart type
13
var chart = anychart.area();
14
15
chart.title("Append Point Demo");
16
17
// set data
18
var area = chart.splineArea(data);
19
20
// set container and draw chart
21
chart.container("container").draw();
22
});
23
24
// function, if listener triggers
25
function addPoint() {
26
// first index for new point
27
newIndex = (data.mapAs().getRowsCount())+1;
28
29
// append data
30
data.append({
31
32
// x value
33
x: "new P" + newIndex,
34
35
// random value from 1 to 100
36
value : Math.floor((Math.random() * 100)+ 1)
37
});
38
};