bubble-port.html~ 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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: 53px; /* chartArea top */
  20. left: 528px; /* 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. /*
  47. setInterval(function() {
  48. placeIndexMarker();
  49. }, 2000);
  50. */
  51. function placeIndexMarker() {
  52. $.ajax({
  53. type: 'Post',
  54. url: '/ws_market_data?r_ckey={{{FUT_CONTRACT}}}&fid=4',
  55. success: function (data) {
  56. var spot = data
  57. $('#spot').text(spot);
  58. var cli = chart.getChartLayoutInterface();
  59. document.querySelector('.overlay-marker').style.top = Math.floor(cli.getYLocation(0) - 45) + "px";
  60. document.querySelector('.overlay-marker').style.left = Math.floor(cli.getXLocation(spot)) + "px";
  61. }
  62. });
  63. }
  64. //https://groups.google.com/forum/#!msg/google-chart-api/yYxkv4eorhA/P-MHQOLA19MJ
  65. /* testing
  66. function placeMarker() {
  67. var cli = chart.getChartLayoutInterface();
  68. document.querySelector('.overlay-marker').style.top = Math.floor(cli.getYLocation(0) - 25) + "px";
  69. var spot = Math.round(Math.max(25000 * Math.random(), 15000))
  70. $('#pt_status').text(spot);
  71. $('#spot').text(spot);
  72. document.querySelector('.overlay-marker').style.left = Math.floor(cli.getXLocation(spot)) + "px";
  73. };
  74. var cli = chart.getChartLayoutInterface();
  75. var l= cli.getChartAreaBoundingBox().left;
  76. var t=cli.getChartAreaBoundingBox().top;
  77. var h=cli.getChartAreaBoundingBox().height;
  78. var w= cli.getChartAreaBoundingBox().width;
  79. var hx = cli.getYLocation(50000);
  80. var cx = cli.getYLocation(0);
  81. $('#pt_status').text(l + ':' + t + ':' + h + ':' + w + ':' + hx + ':' + cx);
  82. function chartMouseOver(e) {
  83. var cli = chart.getChartLayoutInterface();
  84. var xx = Math.floor(cli.getXLocation(e['row'])) + 'px';
  85. var yy = Math.floor(cli.getYLocation(data.getValue(e['row'], 1))) + 'px';
  86. $('#pt_status').text(e['row'] + ':' + xx + + ':' + yy + ':' + data.getValue(e['row'], 1));
  87. $('#pt2_status').text(e['row'] + ':' + cli.getHAxisValue(e['row']));
  88. }
  89. */
  90. } // end drawChart
  91. </script>
  92. </head>
  93. <body>
  94. <div id='pt_status'></div>
  95. <div id='pt2_status'></div>
  96. <div id="chart_div" style="width: 900px; height: 800px;"></div>
  97. <div id='temp'></div>
  98. <div class="overlay-marker">
  99. <img src="/public/green_marker.png" height="50"><div id='spot'></div>
  100. </div>
  101. </body>
  102. </html>