bubble-port.html 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. <html>
  2. <head>
  3. <style>
  4. .chartWithMarkerOverlay {
  5. position: relative;
  6. width: 700px;
  7. }
  8. .overlay-text {
  9. width: 200px;
  10. height: 200px;
  11. position: absolute;
  12. top: 30px; /* chartArea top */
  13. left: 200px; /* chartArea left */
  14. }
  15. .overlay-marker {
  16. width: 50px;
  17. height: 50px;
  18. position: absolute;
  19. top: 375px; /* chartArea top */
  20. left: 350px; /* chartArea left */
  21. color: #000066;
  22. font: 15px arial;
  23. }
  24. </style>
  25. <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
  26. <script type="text/javascript" src="https://www.google.com/jsapi"></script>
  27. <script type="text/javascript">
  28. google.load("visualization", "1.1", {packages:['corechart']});
  29. google.setOnLoadCallback(drawChart);
  30. function drawChart() {
  31. ////////////////////////////////////////////////////////////////////////////////
  32. // guage functions
  33. var data = google.visualization.arrayToDataTable(
  34. {{{bubble_data}}}
  35. );
  36. var options = { title: 'Portfolio Risk Distribution',
  37. hAxis: {title: 'Strike Price'}, vAxis: {title: ' Unreal P/L'},
  38. // to display labels, remove the color: 'none option
  39. bubble: {textStyle: {fontSize: 11, color: 'none'}}, colorAxis: {colors: ['red', 'blue']},
  40. sizeAxis: {minValue: 2, maxSize: 40}
  41. //backgroundColor: '#E4E4E4'
  42. };
  43. var chart = new google.visualization.BubbleChart(document.getElementById('chart_div'));
  44. chart.draw(data, options);
  45. google.visualization.events.addListener(chart, 'ready', placeIndexMarker);
  46. var button = document.getElementById('b1');
  47. button.onclick = function() {
  48. refreshPortItems();
  49. refreshAcctItems();
  50. }
  51. setInterval(function() {
  52. placeIndexMarker();
  53. }, 2000);
  54. function refreshPortItems() {
  55. $.ajax({
  56. type: 'Post',
  57. url: '/ws_bubble_data',
  58. success: function (s_portitems) {
  59. //$('#pt_status').text(s_portitems);
  60. //alert(jdata.delta_all);
  61. lst = eval(s_portitems);
  62. //alert(lst[0]);
  63. data = google.visualization.arrayToDataTable(eval(s_portitems));
  64. chart.draw(data, options);
  65. drawChart();
  66. }
  67. });
  68. }
  69. function refreshAcctItems() {
  70. $.ajax({
  71. type: 'Post',
  72. url: '/ws_acct_data',
  73. success: function (s_accttitems) {
  74. //$('#pt_status').text(s_accttitems);
  75. //alert(jdata.delta_all);
  76. lst = eval(s_portitems);
  77. //alert(lst[0]);
  78. dataB = google.visualization.arrayToDataTable(eval(s_accttitems));
  79. chart.draw(dataB, options);
  80. drawChart();
  81. }
  82. });
  83. }
  84. function placeIndexMarker(){
  85. $.ajax({
  86. type: 'Post',
  87. url: '/ws_market_data?r_ckey={{{FUT_CONTRACT}}}&fid=4',
  88. success: function (data) {
  89. var spot = data
  90. $('#spot').text(spot);
  91. var cli = chart.getChartLayoutInterface();
  92. document.querySelector('.overlay-marker').style.top = Math.floor(cli.getYLocation(0) - 25) + "px";
  93. document.querySelector('.overlay-marker').style.left = Math.floor(cli.getXLocation(spot) - 25) + "px";
  94. }
  95. });
  96. var dataB = google.visualization.arrayToDataTable(
  97. {{{barAcct}}}
  98. );
  99. var view = new google.visualization.DataView(dataB);
  100. view.setColumns([0, 1,
  101. { calc: "stringify",
  102. sourceColumn: 1,
  103. type: "string",
  104. role: "annotation" }, 2]);
  105. var options = {
  106. chart: {
  107. title: 'Account Summary {{{account_no}}}',
  108. subtitle: 'Last updated {{{last_updated}}}'
  109. },
  110. bars: 'horizontal',bar: {groupWidth: "55%"},
  111. legend: { position: "none" },
  112. };
  113. var material = new google.visualization.BarChart(document.getElementById('barchart_div'));
  114. material.draw(view, options);
  115. }
  116. //https://groups.google.com/forum/#!msg/google-chart-api/yYxkv4eorhA/P-MHQOLA19MJ
  117. /* testing
  118. function placeMarker() {
  119. var cli = chart.getChartLayoutInterface();
  120. document.querySelector('.overlay-marker').style.top = Math.floor(cli.getYLocation(0) - 25) + "px";
  121. var spot = Math.round(Math.max(25000 * Math.random(), 15000))
  122. $('#pt_status').text(spot);
  123. $('#spot').text(spot);
  124. document.querySelector('.overlay-marker').style.left = Math.floor(cli.getXLocation(spot)) + "px";
  125. };
  126. var cli = chart.getChartLayoutInterface();
  127. var l= cli.getChartAreaBoundingBox().left;
  128. var t=cli.getChartAreaBoundingBox().top;
  129. var h=cli.getChartAreaBoundingBox().height;
  130. var w= cli.getChartAreaBoundingBox().width;
  131. var hx = cli.getYLocation(50000);
  132. var cx = cli.getYLocation(0);
  133. $('#pt_status').text(l + ':' + t + ':' + h + ':' + w + ':' + hx + ':' + cx);
  134. function chartMouseOver(e) {
  135. var cli = chart.getChartLayoutInterface();
  136. var xx = Math.floor(cli.getXLocation(e['row'])) + 'px';
  137. var yy = Math.floor(cli.getYLocation(data.getValue(e['row'], 1))) + 'px';
  138. $('#pt_status').text(e['row'] + ':' + xx + + ':' + yy + ':' + data.getValue(e['row'], 1));
  139. $('#pt2_status').text(e['row'] + ':' + cli.getHAxisValue(e['row']));
  140. }
  141. */
  142. } // end drawChart
  143. </script>
  144. </head>
  145. <body>
  146. <div id='pt2_status'></div>
  147. <button type='button' id='b1'>Update Charts</button>
  148. <div id="chart_div" style="width: 900px; height: 800px;"></div>
  149. <div id="barchart_div" style="width:800px; height: 600px;"></div>
  150. <div id='temp'></div>
  151. <div class="overlay-marker">
  152. <img src="/public/green_marker.png" height="50"><div id='spot'></div>
  153. </div>
  154. <div id='pt_status'></div>
  155. </body>
  156. </html>