2011-04-06 73 views
46

有誰知道如何在Flot中設置軸的標籤或標題?Flot中的軸標籤

我讀過的API,但它似乎不具備該功能...

謝謝:)

回答

37

有沒有內置在海軍報。

最好的選擇是通過定位div來自己做,但如果你喜歡冒險,你可以看看issue(或原始issue),看看其他人如何處理它。

具體來說,有誰最近製作好的標籤相關修訂海軍報兩個人:

https://github.com/RuiPereira/flot/raw/axislabels/jquery.flot.axislabels.js

http://github.com/xuanluo/flot-axislabels

+0

我要試着用定位的div來做自己。謝謝。 – Nobita 2011-04-06 15:43:31

+0

[主頁](http://www.flotcharts.org/)上的y軸標籤正如本答案所述:通過仔細定位的div完成。然而,似乎[版本0.9的Flot將包含軸標籤](https://github.com/flot/flot/pull/1090)。 – 2013-09-11 09:50:19

+0

謝謝@MatthewWalker - 一次0。9發佈後,我會更新我的回答 – Ryley 2013-09-11 15:59:30

1

jqPlot已經支持這一點,櫃面你能夠使用替代

http://www.jqplot.com

+0

+1。太奇妙了。 – 2012-05-21 15:36:03

+1

一個潛在的缺點,對任何人都應該是重要的是Flot仍然支持IE6,而jqPlot已經放棄了它。 – Cheekysoft 2012-10-30 10:38:00

+1

什麼也說爲Flot是更好的平移和縮放的方式。 [This](http://www.flotcharts.org/flot/examples/navigate/index.html)比[that](http://www.jqplot.com/tests/zooming.php)更直觀。 – Axel 2015-01-23 09:51:53

34

我使用這個workarou nd:

yaxis: { 
tickFormatter: function(val, axis) { return val < axis.max ? val.toFixed(2) : "CZK/l";} 
} 

非常簡單,Y軸上的最大值被自定義字符串替代。我沒有在X軸上進行測試,但我沒有看到爲什麼它不起作用。

+0

感謝您的幫助,+1 – abhijit 2013-06-03 13:46:42

+0

聰明!我喜歡。 – Cheezmeister 2013-08-12 17:12:03

+0

可悲的是,它並沒有顯示在我的身上,因爲Flot決定隱藏圖 – Dennis 2014-09-23 20:06:30

31

無恥自插:我修正並大大擴展了xuanluo的flot-axislabels插件:http://github.com/markrcote/flot-axislabels/據我所知,這是目前軸標最好的解決方案。

+0

這對我而言是無效的。 methinks這可以被接受的答案 – Dennis 2014-09-23 20:37:27

+0

應該是被接受的答案。整合是無痛的 – 2016-10-07 16:38:35

5

我看到一個很好的建議是把圖放在3x3表的中間。然後標籤可以放在其他單元格中。

<table style="text-align:center"> 
    <tr> 
    <td></td> 

    <td>Plot Title Goes Here</td> 

    <td> </td> 
    </tr> 

    <tr> 
    <td>Y Axis Label</td> 

    <td> 
     <div id="graph here" style="width:600px;height:300px"></div> 
    </td> 

    <td></td> 
    </tr> 

    <tr> 
    <td></td> 

    <td>X Axis Label Goes Here</td> 

    <td></td> 
    </tr> 

</table> 
+0

一個體面的解決方法。我認爲對於Y軸,也許使用一個圖像,以便您可以垂直。 – Orion 2017-12-22 21:35:45

0
$("<div class='axisLabel yaxisLabel'></div>") 
     .text("Pressure") 
     .appendTo($("#yl_1")); 

這將工作過。

1

示例純CSS解決2dims圖(x和y軸)。

Y軸:

#placeholder:after { 
    content: 'Speed'; 
    position: absolute; 
    top: 50%; 
    left: -50px; 
    font-weight: 600; 
    /* Safari */ 
    -webkit-transform: rotate(-90deg); 
    /* Firefox */ 
    -moz-transform: rotate(-90deg); 
    /* IE */ 
    -ms-transform: rotate(-90deg); 
    /* Opera */ 
    -o-transform: rotate(-90deg); 
    /* Internet Explorer */ 
    filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=3); 
} 

X軸:

#placeholder:before { 
    content: 'Time'; 
    position: absolute; 
    bottom: -30px; 
    left: 50%; 
    font-weight: 600; 
} 
0

我用szpapas想法。

我在下面添加了更多的jquery代碼來覆蓋x軸。

  $('div.flot-x-axis div.flot-tick-label.tickLabel:nth-child(1)').html("Berhad") 
      $('div.flot-x-axis div.flot-tick-label.tickLabel:nth-child(2)').html("") 
      $('div.flot-x-axis div.flot-tick-label.tickLabel:nth-child(3)').html("Sdn Bhd") 
      $('div.flot-x-axis div.flot-tick-label.tickLabel:nth-child(4)').html("") 
      $('div.flot-x-axis div.flot-tick-label.tickLabel:nth-child(5)').html("Enterprise") 
      $('div.flot-x-axis div.flot-tick-label.tickLabel:nth-child(6)').html("") 
      $('div.flot-x-axis div.flot-tick-label.tickLabel:nth-child(7)').html("Koperasi")