HTMLcopy
1
<div id="tablePlaceholder"></div>
2
<div id="container"></div>
CSScopy
27
1
html, body {
2
width: 100%;
3
height: 100%;
4
margin: 0;
5
padding: 0;
6
}
7
table {
8
9
}
10
caption {
11
font-weight: 600;
12
padding-bottom: 10px;
13
}
14
#container {
15
position: absolute;
16
width: 60%;
17
top: 0;
18
bottom: 0;
19
}
20
#tableInfo {
21
position: absolute;
22
width: 40%;
23
top: 22px;
24
right: 0;
25
bottom: 0;
26
color: #990000;
27
}
JavaScriptcopy
x
1
anychart.onDocumentReady(function () {
2
3
// create a data table
4
var dataTable = anychart.data.table(0);
5
6
// create a data table
7
var dataTable = anychart.data.table();
8
9
// add data from the CDN
10
// https://cdn.anychart.com/csv-data/csco-daily.js
11
dataTable.addData(get_csco_daily_data());
12
13
// map the data
14
mapping = dataTable.mapAs({low: 3, high: 2});
15
16
// create a stock chart
17
chart = anychart.stock();
18
19
// create a plot and a range area series
20
var ohlcSeries = chart.plot(0).rangeArea(mapping);
21
ohlcSeries.name("CSCO");
22
23
// set the chart title
24
chart.title("Table Data: Iterating");
25
26
// set the range of points shown on the chart
27
chart.selectRange("2002-01-01", "2006-01-01");
28
29
// display information about shown points
30
showSelected();
31
32
/* listen to changing the shown range of points
33
and update the displayed information */
34
chart.listen("selectedRangeChange", function(){
35
showSelected();
36
});
37
38
// set the container id
39
chart.container("container");
40
41
// initiate drawing the chart
42
chart.draw();
43
});
44
45
// display information about shown points
46
function showSelected() {
47
48
// create a table for displaying information
49
var tablePlaceholder = document.getElementById("tablePlaceholder");
50
tablePlaceholder.innerHTML = "<table id='tableInfo'>" +
51
"<caption>Shown Points</caption>" +
52
"<tr><td>Date</td><td>Low</td>" +
53
"<td>High</td></tr></table>";
54
55
// get the shown range of points
56
var range = chart.getSelectedRange();
57
58
/* create the selectable object,
59
select rows corresponding to the shown points, and group them */
60
selectable = mapping.createSelectable();
61
selectable.select(range.firstSelected, range.lastSelected, "year", 2);
62
63
// get the iterator
64
var iterator = selectable.getIterator();
65
66
// get the table for displaying information
67
var tableInfo = document.getElementById("tableInfo");
68
69
// display information about shown points in the table
70
while (iterator.advance()) {
71
var key = iterator.getKey();
72
var date = anychart.format.dateTime(key, "dd.MM.yyyy");
73
var low = iterator.get("low");
74
var high = iterator.get("high");
75
var newRow = document.createElement("tr");
76
var newColumnDate = document.createElement("td");
77
var newColumnLow = document.createElement("td");
78
var newColumnHigh = document.createElement("td");
79
newColumnDate.innerText = date;
80
newColumnLow.innerText = low;
81
newColumnHigh.innerText = high;
82
newRow.appendChild(newColumnDate);
83
newRow.appendChild(newColumnLow);
84
newRow.appendChild(newColumnHigh);
85
tableInfo.appendChild(newRow);
86
}
87
}