2012-07-04 146 views
1

我正在使用在不規則位置有tickmarks的flot進行繪圖,例如,一個在位置100,一個在位置155,一個在位置230.Flot能夠輕鬆地在這些位置放置蜱標記。定位flot xaxis標籤

但我想把軸標籤放在這些點之間,例如,

|--------------|-------|------------------| 
    blahblah  huh  metoo 

無法弄清楚如何獲得flot。任何消化?

感謝

回答

1

它使用海軍報的多軸功能,添加第二個軸與您的標籤:

enter image description here

代碼:

 $.plot($("#placeholder"), 
     [ { data: [[1,1],[12,12],[45,45],[2,2],[7,7],[90,90],[112,112],[145,145],[87,87],[250,250]]}, 
     { data: [[]], xaxis: 2}], //second empty series 
      { 
       xaxes: [ {ticks:[100,155,230]}, // force tick location 
         {ticks: [50,127.5,192.5], // label locations, center them based on forced tick locations 
         min: 0, max: 250, // set min and max to scale 2nd axis 
         tickFormatter: // return string label instead of number 
          function formatter(val, axis) { 
          if (val == 50) return "blahblah"; 
          else if (val == 127.5) return "huh"; 
          else if (val == 192.5) return "metoo"; 
          else return ""; 
          }} ] 
      });​ 

小提琴here