java 如何更改 JFreeChart 中 NumberAxis 上的刻度标签?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2365657/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 20:47:45  来源:igfitidea点击:

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

javajfreechart

提问by Tony Eichelberger

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.

我正在使用 JFreeChart 并希望能够将范围轴上的标签从数字更改为对我所在的域更有意义的内容。我只能看到用于自定义标签外观的选项,而无法覆盖基于刻度位置的标签。

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

有谁知道如何覆盖 tickLabel 的文本?

回答by trashgod

The JFreeChart BarChartDemo1shows how to use the setStandardTickUnits()method. NumberAxishas several handy static factories for this. To override the defaults, you can "create your own instance of TickUnitsand then pass it to the setStandardTickUnits()method."

JFreeChartBarChartDemo1展示了如何使用该setStandardTickUnits()方法。NumberAxis有几个方便的静态工厂。要覆盖默认值,您可以“创建自己的实例,TickUnits然后将其传递给setStandardTickUnits()方法”。

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

附录:上面提到的默认值只是使用java.text.Format;的子类。你可以为每个TickUnit你提供你自己的add()。如果这还不够,您可以valueToString()在您自己的具体子类中覆盖TickUnit并使用它来组合所需的TickUnits.

回答by chris

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

我刚刚在遇到同样的问题时发现了这个。我通过使用SymbolAxis. SymbolAxis可以添加到XYPlot.

SymbolAxis sa = new SymbolAxis("AxisLabel",
    new String[]{"Category1","Category2","Category3","..."});
chart.getPlot().setDomainAxis(sa);