Merge pull request #557 from danvk/sync-glitch
[dygraphs.git] / tests / gviz-selection.html
... / ...
CommitLineData
1<!DOCTYPE html>
2<html>
3 <head>
4 <title>gviz selection</title>
5 <!--
6 For production (minified) code, use:
7 <script type="text/javascript" src="dygraph-combined.js"></script>
8 -->
9 <script type="text/javascript" src="../dygraph-dev.js"></script>
10
11 <script type="text/javascript" src="http://www.google.com/jsapi"></script>
12 <script type="text/javascript">
13 google.load('visualization', '1');
14
15 function createDataTable(dateType) {
16 data = new google.visualization.DataTable();
17 data.addColumn(dateType, 'Date');
18 data.addColumn('number', 'Column A');
19 data.addColumn('number', 'Column B');
20 data.addRows(10);
21 data.setCell(0, 0, new Date("2009/07/01"));
22 data.setCell(0, 1, 1);
23 data.setCell(0, 2, 7);
24 data.setCell(1, 0, new Date("2009/07/08"));
25 data.setCell(1, 1, 2);
26 data.setCell(1, 2, 4);
27 data.setCell(2, 0, new Date("2009/07/15"));
28 data.setCell(2, 1, 3);
29 data.setCell(2, 2, 3);
30 data.setCell(3, 0, new Date("2009/07/22"));
31 data.setCell(3, 1, 4);
32 data.setCell(3, 2, 0);
33 data.setCell(4, 0, new Date("2009/07/26"));
34 data.setCell(4, 1, 5);
35 data.setCell(4, 2, 2);
36 data.setCell(5, 0, new Date("2009/07/27"));
37 data.setCell(5, 1, 2);
38 data.setCell(5, 2, 7);
39 data.setCell(6, 0, new Date("2009/07/28"));
40 data.setCell(6, 1, 3);
41 data.setCell(6, 2, 8);
42 data.setCell(7, 0, new Date("2009/08/01"));
43 data.setCell(7, 1, 4);
44 data.setCell(7, 2, 9);
45 data.setCell(8, 0, new Date("2009/08/02"));
46 data.setCell(8, 1, 3);
47 data.setCell(8, 2, 10);
48 data.setCell(9, 0, new Date("2009/08/04"));
49 data.setCell(9, 1, 3);
50 data.setCell(9, 2, 8);
51 return data;
52 }
53
54 var chart;
55
56 function drawVisualization() {
57 data = createDataTable('date');
58
59 chart = new Dygraph.GVizChart(document.getElementById('dygraphs'));
60 chart.draw(data, {hideOverlayOnMouseOut: false});
61
62 }
63
64 function setSelection() {
65 var sel = [{column: 1, row: 2}, {column: 2, row: 2}];
66 chart.setSelection(sel);
67 }
68 function clearSelection() {
69 var sel = [];
70 chart.setSelection(sel);
71 }
72 function getChartSelection() {
73 var sel = chart.getSelection();
74
75 var html = '<p>Selection: [';
76 for (var i = 0; i < sel.length; i++) {
77 if (i > 0) html += ', ';
78 html += i + '=&gt; {row: '+ sel[i].row +
79 ' col: '+ sel[i].column + '}';
80 }
81 html += ']</p>';
82 document.getElementById('output').innerHTML += html;
83 }
84 google.setOnLoadCallback(drawVisualization);
85 </script>
86 </head>
87 <body>
88 <p>Get/Set/Clear selection via gviz API:</p>
89 <div id="dygraphs" style="width:600px; height:300px;"></div>
90 <input type="button" onclick="setSelection()" value="setSelection()"/>
91 <input type="button" onclick="clearSelection()" value="clearSelection()"/>
92 <input type="button" onclick="getChartSelection()" value="getSelection()"/>
93 <div id="output"></div>
94 </body>
95</html>