You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

hBar_side.js 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. $(function () {
  2. var previousPoint;
  3. //Display horizontal graph
  4. var d1_h = [];
  5. for (var i = 0; i <= 3; i += 1)
  6. d1_h.push([parseInt(Math.random() * 30),i ]);
  7. var d2_h = [];
  8. for (var i = 0; i <= 3; i += 1)
  9. d2_h.push([parseInt(Math.random() * 30),i ]);
  10. var d3_h = [];
  11. for (var i = 0; i <= 3; i += 1)
  12. d3_h.push([ parseInt(Math.random() * 30),i]);
  13. var ds_h = new Array();
  14. ds_h.push({
  15. data:d1_h,
  16. bars: {
  17. horizontal:true,
  18. show: true,
  19. barWidth: 0.2,
  20. order: 1,
  21. }
  22. });
  23. ds_h.push({
  24. data:d2_h,
  25. bars: {
  26. horizontal:true,
  27. show: true,
  28. barWidth: 0.2,
  29. order: 2
  30. }
  31. });
  32. ds_h.push({
  33. data:d3_h,
  34. bars: {
  35. horizontal:true,
  36. show: true,
  37. barWidth: 0.2,
  38. order: 3
  39. }
  40. });
  41. //tooltip function
  42. function showTooltip(x, y, contents, areAbsoluteXY) {
  43. var rootElt = 'body';
  44. $('<div id="tooltip3" class="tooltip">' + contents + '</div>').css( {
  45. position: 'absolute',
  46. display: 'none',
  47. top: y - 35,
  48. left: x - 5,
  49. 'z-index': '9999',
  50. 'color': '#fff',
  51. 'font-size': '11px',
  52. opacity: 0.8
  53. }).prependTo(rootElt).show();
  54. }
  55. $.plot($("#placeholder1_hS"), ds_h, {
  56. grid:{
  57. hoverable:true
  58. }
  59. });
  60. //add tooltip event
  61. $("#placeholder1_hS").bind("plothover", function (event, pos, item) {
  62. if (item) {
  63. if (previousPoint != item.datapoint) {
  64. previousPoint = item.datapoint;
  65. //delete de prГ©cГ©dente tooltip
  66. $('.tooltip').remove();
  67. var x = item.datapoint[0];
  68. //All the bars concerning a same x value must display a tooltip with this value and not the shifted value
  69. if(item.series.bars.order){
  70. for(var i=0; i < item.series.data.length; i++){
  71. if(item.series.data[i][3] == item.datapoint[0])
  72. x = item.series.data[i][0];
  73. }
  74. }
  75. var y = item.datapoint[1];
  76. showTooltip(item.pageX+5, item.pageY+5,x + " = " + y);
  77. }
  78. }
  79. else {
  80. $('.tooltip').remove();
  81. previousPoint = null;
  82. }
  83. });
  84. });