add public interface; add cssClass property
[dygraphs.git] / tests / annotation.html
1 <html>
2 <head>
3 <title>demo</title>
4 <!--[if IE]>
5 <script type="text/javascript" src="excanvas.js"></script>
6 <![endif]-->
7 <script type="text/javascript" src="../strftime/strftime-min.js"></script>
8 <script type="text/javascript" src="../rgbcolor/rgbcolor.js"></script>
9 <script type="text/javascript" src="../dygraph-canvas.js"></script>
10 <script type="text/javascript" src="../dygraph.js"></script>
11 <style type="text/css">
12 .annotation {
13 background-color: #dddddd
14 }
15 </style>
16 </head>
17 <body>
18 <div style="position:absolute; left:100px; top: 200px;" id="g"></div>
19 <div style="position:absolute; left:600px; top: 200px;" id="list"></div>
20
21 <script type="text/javascript">
22 g = new DateGraph(
23 document.getElementById("g"),
24 function() {
25 var zp = function(x) { if (x < 10) return "0"+x; else return x; };
26 var r = "date,parabola,line,another line,sine wave\n";
27 for (var i=1; i<=31; i++) {
28 r += "200610" + zp(i);
29 r += "," + 10*(i*(31-i));
30 r += "," + 10*(8*i);
31 r += "," + 10*(250 - 8*i);
32 r += "," + 10*(125 + 125 * Math.sin(0.3*i));
33 r += "\n";
34 }
35 return r;
36 },
37 {
38 rollPeriod: 1,
39 showRoller: true,
40 width: 480,
41 height: 320,
42 drawCallback: function(g) {
43 var ann = g.annotations();
44 var html = "";
45 for (var i = 0; i < ann.length; i++) {
46 html += "(" + ann[i].series + ", " + ann[i].x + "): " + ann[i].shortText + " -> " + ann[i].text + "<br/>";
47 }
48 document.getElementById("list").innerHTML = html;
49 },
50 }
51 );
52
53 var last_ann = 0;
54 annotations = [];
55 for (var x = 10; x < 15; x += 2) {
56 annotations.push( {
57 series: 'sine wave',
58 x: "200610" + x,
59 shortText: x,
60 text: 'Stock Market Crash ' + x
61 } );
62 last_ann = x;
63 }
64 annotations.push( {
65 series: 'another line',
66 x: "20061013",
67 shortText: 'X',
68 text: 'Another one',
69 cssClass: 'annotation'
70 } );
71 g.setAnnotations(annotations);
72
73 function add() {
74 var x = last_ann + 2;
75 var annnotations = g.annotations();
76 annotations.push( {
77 series: 'line',
78 x: "200610" + x,
79 shortText: x,
80 text: 'Line ' + x
81 } );
82 last_ann = x;
83 g.setAnnotations(annotations);
84 }
85 </script>
86
87 <input type="button" value="Add Annotation" onclick="add()" />
88 </body>
89 </html>