Axis label in Flot

后端 未结 9 1175
长情又很酷
长情又很酷 2021-01-31 14:15

Does anyone know how one can set the label or title of an axis in Flot?

I\'ve read the API but it doesn\'t seem to have that feature...

Thanks :)

相关标签:
9条回答
  • 2021-01-31 14:43

    i'm using this workaround:

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

    Very simple, the max value on the Y axis is replaced by a custom string. I've not tested on the X axis, but I see no reason why it shouldn't work.

    0 讨论(0)
  • 2021-01-31 14:48

    This one has fixes for using multiple axes and the offset works well too... https://github.com/mikeslim7/flot-axislabels

    0 讨论(0)
  • 2021-01-31 14:50

    There are none built-in to flot.

    Your best bet is to do it yourself via positioned divs, but if you are adventurous, you can look at the issue (Or the original issue) and see how other people have dealt with it.

    Specifically, there are two people who have recently made label-related revisions to flot:

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

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

    0 讨论(0)
  • 2021-01-31 14:51

    jqPlot has support for this, incase you're able to use an alternative

    http://www.jqplot.com

    0 讨论(0)
  • 2021-01-31 14:53

    Shameless self-plug: I fixed and greatly extended xuanluo's flot-axislabels plugin: http://github.com/markrcote/flot-axislabels/ As far as I know, it is the best solution for axis labels at the moment.

    0 讨论(0)
  • 2021-01-31 15:00

    I use szpapas idea.

    I added more jquery code below it to overwrite x-axis like this.

                $('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")
    
    0 讨论(0)
提交回复
热议问题