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
// create data
4
var data = [
5
{x: 0.6, value: 22},
6
{x: 1.7, value: 55},
7
{x: 2.3, value: 50},
8
{x: 3.5, value: 80},
9
{x: 3.9, value: 74},
10
{x: 4, value: 68},
11
{x: 4, value: 76},
12
{x: 4.1, value: 84},
13
{x: 4.7, value: 93}
14
];
15
16
// create a chart
17
var chart = anychart.scatter();
18
19
// create a marker series and set the data
20
var series = chart.marker(data);
21
22
// access the annotations() object of the chart to work with annotations
23
var controller = chart.annotations();
24
25
// create an ellipse annotation
26
var ellipse = controller.ellipse({
27
xAnchor: "1.5",
28
valueAnchor: 45,
29
secondXAnchor: "2.6",
30
secondValueAnchor: 62,
31
fill: {opacity: 0},
32
stroke: "2 red"
33
});
34
35
// create a rectangle annotation
36
var rectangle = controller.rectangle({
37
xAnchor: "3.3",
38
valueAnchor: 64,
39
secondXAnchor: "4.4",
40
secondValueAnchor: 88,
41
fill: {opacity: 0},
42
stroke: "2 red"
43
});
44
45
// disable interactivity for the ellipse annotation
46
ellipse.allowEdit(false);
47
48
// disable interactivity for the rectangle annotation
49
rectangle.allowEdit(false);
50
51
// create major grids and bind them to the X and Y axes
52
chart.grid(0).axis(chart.xAxis());
53
chart.grid(1).axis(chart.yAxis());
54
55
// create minor grids and bind them to the X and Y axes
56
chart.minorGrid(0).axis(chart.xAxis());
57
chart.minorGrid(1).axis(chart.yAxis());
58
59
// set the chart title
60
chart.title("Scatter Plot: Annotations");
61
62
// set the container id
63
chart.container("container");
64
65
// initiate drawing the chart
66
chart.draw();
67
});