How can I change the tickLabel on a NumberAxis in JFreeChart?
Asked Answered
I

2

5

I am using JFreeChart and want to be able to change the label on the range axis from a number to something more meaningful for the domain I am in. I only see options for customizing the look of the label and no way to override the content of the label based on the position of the tick.

Does anyone know how to override the text of the tickLabel?

Ignite answered 2/3, 2010 at 18:31 Comment(0)
H
8

The JFreeChart BarChartDemo1 shows how to use the setStandardTickUnits() method. NumberAxis has several handy static factories for this. To override the defaults, you can "create your own instance of TickUnits and then pass it to the setStandardTickUnits() method."

Addendum: The defaults mentioned above simply use a subclass of java.text.Format; you can supply your own for each TickUnit you add(). If this is inadequate, you can override valueToString() in your own concrete subclass of TickUnit and use it to compose the required TickUnits.

Heliotaxis answered 2/3, 2010 at 21:13 Comment(1)
Not as easy as I was hoping for, but this is great! Thanks.Ignite
L
5

I just found this while having the same problem. I solved it by using a SymbolAxis. SymbolAxis can be added to a XYPlot.

SymbolAxis sa = new SymbolAxis("AxisLabel",
    new String[]{"Category1","Category2","Category3","..."});
chart.getPlot().setDomainAxis(sa);
Leventhal answered 1/9, 2010 at 0:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.