HTMLcopy
1
<div id="container"></div>
CSScopy
6
1
html, body, #container {
2
width: 100%;
3
height: 100%;
4
margin: 0;
5
padding: 0;
6
}
JavaScriptcopy
x
1
anychart.onDocumentReady(function () {
2
3
var dataSet = anychart.data.set([
4
{x: "P1", value: 100},
5
{x: "P2", value: 200},
6
{x: "P3", value: 15},
7
{x: "P4", value: 130},
8
{x: "P5", value: 153},
9
{x: "P6", value: 120},
10
{x: "P7", value: 151},
11
{x: "P8", value: 58},
12
{x: "P9", value: 19},
13
{x: "P10", value: 135},
14
{x: "P11", value: 170},
15
{x: "P12", value: 195},
16
{x: "P13", value: 22},
17
{x: "P14", value: 175},
18
{x: "P15", value: 120}
19
]);
20
21
// set chart type
22
var chart = anychart.area();
23
24
chart.title("Move the Mouse to Add Points, Click to stop it");
25
26
// set data
27
chart.splineArea(dataSet);
28
29
// disable stagger mode. Only one line for x axis labels
30
var xAxis = chart.xAxis();
31
xAxis.staggerMode(false);
32
33
// set container and draw chart
34
chart.container("container").draw();
35
36
// first index for new point
37
var indexSetter = 16;
38
39
// create a function what to listen and then unlisten
40
var func_listen = function() {
41
dataSet.append({
42
// x value
43
x: "P" + indexSetter,
44
45
// random value from 1 to 500
46
value : Math.floor((Math.random() * 500)+ 1)
47
});
48
indexSetter++;
49
dataSet.remove(0);
50
};
51
52
// add a listener
53
chart.listen("mouseMove", func_listen);
54
55
chart.listenOnce("click",function() {
56
// adding an unlistener
57
chart.unlisten("mouseMove", func_listen);
58
});
59
60
});