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