HTMLcopy
1
<button id="addButton" onclick="addRow()">Add Row</button>
2
<button id="insertButton" onclick="insertRow()">Insert Row</button>
3
<label>index: <input id="indexInput" value="-1"></label>
4
<div id="container"></div>
CSScopy
22
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
label {
11
margin: 10px 0 0 10px;
12
}
13
input {
14
width: 30px;
15
margin: 10px 0 0 5px;
16
}
17
#container {
18
position: absolute;
19
width: 100%;
20
top: 35px;
21
bottom: 0;
22
}
JavaScriptcopy
x
1
anychart.onDocumentReady(function () {
2
3
// create data
4
data = [
5
["January", 12000],
6
["February", 15000],
7
["March", 16000],
8
["April", 14000],
9
["May", 10000]
10
];
11
12
// create a data set
13
dataSet = anychart.data.set(data);
14
15
// map the data
16
var mapping = dataSet.mapAs({x: 0, value: 1, fill: 2, stroke: 2});
17
18
// create a chart
19
var chart = anychart.column();
20
21
// create a series and set the data
22
var series = chart.column(mapping);
23
24
// set the chart title
25
chart.title("Data Sets: Adding");
26
27
// set the container id
28
chart.container("container");
29
30
// initiate drawing the chart
31
chart.draw();
32
});
33
34
// generate values
35
function getValue() {
36
return Math.floor(Math.random()*7 + 10)*1000;
37
}
38
39
var rowCount = 1;
40
41
// add a new data row
42
function addRow() {
43
var newValue = getValue();
44
var newName = "New " + rowCount++;
45
var newData = [newName, newValue, "#ef6c00"];
46
dataSet.append(newData);
47
}
48
49
// insert a new data row
50
function insertRow() {
51
var index = document.getElementById("indexInput").value;
52
var newValue = getValue();
53
var newName = "New " + rowCount++;
54
var newData = [newName, newValue, "#00bfa5"];
55
dataSet.insert(newData, index);
56
}