HTMLcopy
1
<button id="filterButton" onclick="filterValue()">Filter Data</button>
2
<label>value >= <input id="valueInput" value="14000"></label>
3
<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: 65px;
15
margin: 10px 0 0 5px;
16
}
17
#container {
18
position: absolute;
19
width: 100%;
20
top: 55px;
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
var dataSet = anychart.data.set(data);
14
15
// map the data
16
mapping = dataSet.mapAs({x: 0, value: 1});
17
18
// create a chart
19
chart = anychart.column();
20
21
// create a series and set the data
22
series = chart.column(mapping);
23
24
/* prevent points from being selected
25
when they are clicked on */
26
chart.interactivity().selectionMode("none");
27
28
/* prevent points from being deselected
29
when a click happens outside of them */
30
chart.interactivity().unselectOnClickOutOfPoint(false);
31
32
// set the chart title
33
chart.title().useHtml(true);
34
chart.title("Data Sets: Iterating<br><br>" +
35
"<span style = 'color:#990000'>?</span>");
36
37
// set the container id
38
chart.container("container");
39
40
// initiate drawing the chart
41
chart.draw();
42
});
43
44
/* search for points with values equal or greater than a given one,
45
select them and display their arguments in the chart title */
46
function filterValue() {
47
48
// clear all selections
49
series.unselect();
50
51
// search for points with values equal or greater than a given one
52
var input = document.getElementById("valueInput").value;
53
var newMapping = mapping.filter("value", function(value) {
54
return value >= input;
55
});
56
57
// get the iterator
58
var iterator = newMapping.getIterator();
59
60
// select the points and get their arguments
61
var pointNames = [];
62
while (iterator.advance()) {
63
var name = iterator.get("x");
64
var index = mapping.find("x", name);
65
series.select(index);
66
pointNames.push(name);
67
}
68
69
// create a string displaying the arguments
70
var text = "";
71
if (pointNames.length == 0) {
72
text = "(none)";
73
} else {
74
text = pointNames.join(", ");
75
}
76
77
// update the chart title
78
chart.title("Data Sets: Iterating<br><br><span style = 'color:#990000'>" +
79
text + "</span>");
80
}