/tests/com/google/caja/apitaming/visualization/chart-range-filter.html

http://google-caja.googlecode.com/ · HTML · 111 lines · 96 code · 11 blank · 4 comment · 0 complexity · d533b51f5f9873f15c44d44700fd835c MD5 · raw file

  1. <!--
  2. You are free to copy and use this sample in accordance with the terms of the
  3. Apache license (http://www.apache.org/licenses/LICENSE-2.0.html)
  4. -->
  5. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  6. <html xmlns="http://www.w3.org/1999/xhtml">
  7. <head>
  8. <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
  9. <title>
  10. Google Visualization API Sample
  11. </title>
  12. <script type="text/javascript" src="http://www.google.com/jsapi"></script>
  13. <script type="text/javascript">
  14. google.load('visualization', '1.1', {packages: ['corechart', 'controls']});
  15. </script>
  16. <script type="text/javascript">
  17. function drawVisualization() {
  18. var dashboard = new google.visualization.Dashboard(
  19. document.getElementById('dashboard'));
  20. debugger;
  21. var control = new google.visualization.ControlWrapper({
  22. 'controlType': 'ChartRangeFilter',
  23. 'containerId': 'control',
  24. 'options': {
  25. // Filter by the date axis.
  26. 'filterColumnIndex': 0,
  27. 'ui': {
  28. 'chartType': 'LineChart',
  29. 'chartOptions': {
  30. 'chartArea': {'width': '90%'},
  31. 'hAxis': {'baselineColor': 'none'}
  32. },
  33. // Display a single series that shows the closing value of the stock.
  34. // Thus, this view has two columns: the date (axis) and the stock value (line series).
  35. 'chartView': {
  36. 'columns': [0, 3]
  37. },
  38. // 1 day in milliseconds = 24 * 60 * 60 * 1000 = 86,400,000
  39. 'minRangeSize': 86400000
  40. }
  41. },
  42. // Initial range: 2012-02-09 to 2012-03-20.
  43. 'state': {'range': {'start': new Date(2012, 1, 9), 'end': new Date(2012, 2, 20)}}
  44. });
  45. debugger;
  46. var chart = new google.visualization.ChartWrapper({
  47. 'chartType': 'CandlestickChart',
  48. 'containerId': 'chart',
  49. 'options': {
  50. // Use the same chart area width as the control for axis alignment.
  51. 'chartArea': {'height': '80%', 'width': '90%'},
  52. 'hAxis': {'slantedText': false},
  53. 'vAxis': {'viewWindow': {'min': 0, 'max': 2000}},
  54. 'legend': {'position': 'none'}
  55. },
  56. // Convert the first column from 'date' to 'string'.
  57. 'view': {
  58. 'columns': [
  59. {
  60. 'calc': function(dataTable, rowIndex) {
  61. return dataTable.getFormattedValue(rowIndex, 0);
  62. },
  63. 'type': 'string'
  64. }, 1, 2, 3, 4]
  65. }
  66. });
  67. debugger;
  68. var data = new google.visualization.DataTable();
  69. data.addColumn('date', 'Date');
  70. data.addColumn('number', 'Stock low');
  71. data.addColumn('number', 'Stock open');
  72. data.addColumn('number', 'Stock close');
  73. data.addColumn('number', 'Stock high');
  74. // Create random stock values, just like it works in reality.
  75. var open, close = 300;
  76. var low, high;
  77. for (var day = 1; day < 121; ++day) {
  78. var change = (Math.sin(day / 2.5 + Math.PI) + Math.sin(day / 3) - Math.cos(day * 0.7)) * 150;
  79. change = change >= 0 ? change + 10 : change - 10;
  80. open = close;
  81. close = Math.max(50, open + change);
  82. low = Math.min(open, close) - (Math.cos(day * 1.7) + 1) * 15;
  83. low = Math.max(0, low);
  84. high = Math.max(open, close) + (Math.cos(day * 1.3) + 1) * 15;
  85. var date = new Date(2012, 0 ,day);
  86. data.addRow([date, Math.round(low), Math.round(open), Math.round(close), Math.round(high)]);
  87. }
  88. dashboard.bind(control, chart);
  89. dashboard.draw(data);
  90. }
  91. google.setOnLoadCallback(drawVisualization);
  92. </script>
  93. </head>
  94. <body>
  95. <div id="dashboard">
  96. <div id="chart" style='width: 915px; height: 300px;'></div>
  97. <div id="control" style='width: 915px; height: 50px;'></div>
  98. </div>
  99. </body>
  100. </html>