Formatting Y-axis on JFreeChart

前提是你 提交于 2019-12-02 02:55:29

问题


I have a StackedXYAreaChart similar to the one below:

On the Y-axis, instead of the tick units shown (2.5, 5.0, 7.5, 10.0, etc.), I have the following: 100,000, 200,000, 300,000, 400,000, etc. These represent Bytes, just like the one above. My question is: is there a way I could format these tick units such that they represent Kilobytes, i.e. 100, 200, 300, 400, etc. or even Megabytes, i.e. 0.1, 0.2, 0.3, 0.4, etc.? I don't want to display 10 MB as 10,000,000 on the Y-axis.

Thanks!


回答1:


The static factory createStackedAreaChart() instatiates a NumberAxis for the range. The NumberAxis method createStandardTickUnits() creates the standard tick units, which may serve as an example for creating your own units. In particular, "If you don't like these defaults, create your own instance of TickUnits and then pass it to the setStandardTickUnits() method." There's more details here.




回答2:


I would of done a byte conversion, converting from

KB to MB=(KB/1024)
KB to TB=(KB/(1024*2))
KB to GB=(KB/(1024*3))
KB to PB=(KB/(1024*4))

Where the the NumberAxis should auto range depending on the value passed.



来源:https://stackoverflow.com/questions/7721768/formatting-y-axis-on-jfreechart

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!