2011-11-10 93 views
2

似乎沒有辦法將圖表中的工具提示從右下角顯示出來?這看起來非常直觀,但我無法找到一種方法將其放在數據點的上方或左側。有什麼建議麼?由於FLOT工具提示放置?

我的想法是改變上/下,左/右的功能可按將做到這一點,但沒有運氣

code

function showTooltip(x, y, contents) { 
      $('<div id="tooltip">' + contents + '</div>').css({ 
       position: 'absolute', 
       display: 'none', 
       bottom: y - 35, 
       left: x + 10, 
       border: '1px solid #fdd', 
       padding: '2px', 
       'background-color': '#fee', 
       opacity: 0.80 
      }).appendTo("body").fadeIn(200); 
     } 

code

enter image description here

+0

下面我有工作的工具提示的例子,但不提示放置上面的數據點和向左的問題...任何想法? http://people.iola.dk/olau/flot/examples/interacting.html – Blake

回答

2

使用你的語法,它看起來像combination of top and left它很好(免責聲明,我只有Firefox方便地嘗試它)。

function showTooltip(x, y, contents) { 
     $('<div id="tooltip">' + contents + '</div>').css({ 
      position: 'absolute', 
      display: 'none', 
      top: y - 40, 
      left: x - 100, 
      border: '1px solid #fdd', 
      padding: '2px', 
      'background-color': '#fee', 
      opacity: 0.80 
     }).appendTo("body").fadeIn(200); 

    } 

enter image description here

+0

感謝您的幫助馬克 - 也許它是瀏覽器,因爲它不像IE 8那樣工作。 – Blake

+0

我道歉馬克 - 這在IE中工作。出於某種原因,當我在所有四個圖表上對其進行了更改。不知道發生了什麼,但謝謝! – Blake

0

你應該使用Craig qTip 2插件來獲得更好看的工具提示和(我幾乎肯定)ab從該點移動所需的工具提示。 在這裏你可以找到一個例子:http://craigsworks.com/projects/qtip2/demos/flot和lowwing鏈接把你帶到真棒的整個頁面插件http://craigsworks.com/projects/qtip2/demos/

這是在發佈示例中使用的代碼,也許它可能是你的目的有用...

// Create a tooltip on our chart 
elem.qtip({ 
    prerender: true, 
    content: 'Loading...', // Use a loading message primarily 
    position: { 
     viewport: $(window), // Keep it visible within the window if possible 
     target: 'mouse', // Position it in relation to the mouse 
     adjust: { x: 7 } // ...but adjust it a bit so it doesn't overlap it. 
    }, 
    show: false, // We'll show it programatically, so no show event is needed 
    style: { 
     classes: 'ui-tooltip-shadow ui-tooltip-tipsy', 
     tip: false // Remove the default tip. 
    } 
}); 

我學習很多海軍報的實際應用,所以我們應該保持我們自己聯繫,因爲這插件不具有很大的指導作用。