HTMLcopy
1
<button id="addButton" onclick="addRow()">Add Row</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
// set the default number of digits after the decimal point
4
anychart.format.locales.default.numberLocale.decimalsCount = 2;
5
6
// create a data table
7
dataTable = anychart.data.table(0);
8
9
// add data
10
dataTable.addData([
11
["2015-12-25", 512.53, 514.88, 505.69, 507.34],
12
["2015-12-27", 511.22, 515.30, 505.49, 506.47],
13
["2015-12-28", 510.35, 515.72, 505.23, 505.80],
14
["2015-12-29", 510.53, 515.86, 505.38, 508.25],
15
["2015-12-30", 511.43, 515.98, 505.66, 507.45],
16
["2015-12-31", 511.50, 515.33, 505.99, 507.98],
17
["2016-01-01", 511.32, 514.29, 505.99, 506.37],
18
["2016-01-02", 511.70, 514.87, 506.18, 506.75]
19
]);
20
21
// map the data
22
var mapping = dataTable.mapAs({open: 1, high: 2, low: 3, close: 4,
23
risingStroke: 5, fallingStroke: 5});
24
25
// create a stock chart and allow coloring individual points
26
var chart = anychart.stock(true);
27
28
// create a plot and an ohlc series
29
var ohlcSeries = chart.plot(0).ohlc(mapping);
30
ohlcSeries.name("ACME Corp.");
31
32
// set the chart title
33
chart.title().useHtml(true);
34
chart.title("Table Data: Adding");
35
36
// set the container id
37
chart.container("container");
38
39
// initiate drawing the chart
40
chart.draw();
41
});
42
43
lastDate = new Date(2016, 1, 2);
44
45
// add a new data row
46
function addRow() {
47
var newOpen = (Math.random() * 6) + 507;
48
var newHigh = (Math.random() * 3) + 513;
49
var newLow = (Math.random() * 2) + 505;
50
var newClose = (Math.random() * 6) + 507;
51
var newDate = new Date();
52
newDate.setDate(lastDate.getDate() + 1);
53
lastDate = newDate;
54
//create new data
55
var newData = [[newDate, newOpen, newHigh,
56
newLow, newClose, "4 #00838f"]];
57
// add new data
58
dataTable.addData(newData);
59
}