0
A
回答
1
即將在1.0.18版本是一個新的TickUnitSource的實現,來解決該問題:
/* ===========================================================
* JFreeChart : a free chart library for the Java(tm) platform
* ===========================================================
*
* (C) Copyright 2000-2014, by Object Refinery Limited and Contributors.
*
* Project Info: http://www.jfree.org/jfreechart/index.html
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* [Oracle and Java are registered trademarks of Oracle and/or its affiliates.
* Other names may be trademarks of their respective owners.]
*
* -------------------------
* NumberTickUnitSource.java
* -------------------------
* (C) Copyright 2014, by Object Refinery Limited.
*
* Original Author: David Gilbert (for Object Refinery Limited);
* Contributor(s): -;
*
* Changes
* -------
* 18-Mar-2014 : Version 1 (DG);
*
*/
package org.jfree.chart.axis;
import java.io.Serializable;
import java.text.DecimalFormat;
import java.text.NumberFormat;
/**
* A tick unit source implementation that returns NumberTickUnit instances
* that are multiples of 1 or 5 times some power of 10.
*
* @since 1.0.18
*/
public class NumberTickUnitSource implements TickUnitSource, Serializable {
private int power = 0;
private int factor = 1;
/**
* Creates a new instance.
*/
public NumberTickUnitSource() {
this.power = 0;
this.factor = 1;
}
@Override
public TickUnit getLargerTickUnit(TickUnit unit) {
TickUnit t = getCeilingTickUnit(unit);
if (t.equals(unit)) {
next();
t = new NumberTickUnit(getTickSize(), getTickLabelFormat(),
getMinorTickCount());
}
return t;
}
@Override
public TickUnit getCeilingTickUnit(TickUnit unit) {
return getCeilingTickUnit(unit.getSize());
}
@Override
public TickUnit getCeilingTickUnit(double size) {
this.power = (int) Math.ceil(Math.log10(size));
this.factor = 1;
return new NumberTickUnit(getTickSize(), getTickLabelFormat(),
getMinorTickCount());
}
private boolean next() {
if (factor == 1) {
factor = 5;
return true;
}
if (factor == 5) {
power++;
factor = 1;
return true;
}
throw new IllegalStateException("We should never get here.");
}
private boolean previous() {
if (factor == 1) {
factor = 5;
power--;
return true;
}
if (factor == 5) {
factor = 1;
return true;
}
throw new IllegalStateException("We should never get here.");
}
private double getTickSize() {
return this.factor * Math.pow(10.0, this.power);
}
private DecimalFormat dfNeg4 = new DecimalFormat("0.0000");
private DecimalFormat dfNeg3 = new DecimalFormat("0.000");
private DecimalFormat dfNeg2 = new DecimalFormat("0.00");
private DecimalFormat dfNeg1 = new DecimalFormat("0.0");
private DecimalFormat df0 = new DecimalFormat("#,##0");
private NumberFormat getTickLabelFormat() {
if (power == -4) {
return dfNeg4;
}
if (power == -3) {
return dfNeg3;
}
if (power == -2) {
return dfNeg2;
}
if (power == -1) {
return dfNeg1;
}
if (power >= 0 && power <= 6) {
return df0;
}
return new DecimalFormat("0.#E0");
}
private int getMinorTickCount() {
if (factor == 1) {
return 10;
} else if (factor == 5) {
return 5;
}
return 0;
}
@Override
public boolean equals(Object obj) {
return (obj instanceof NumberTickUnitSource);
}
}
添加到您的代碼:
NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
rangeAxis.setStandardTickUnits(new NumberTickUnitSource());
相關問題
- 1. JFreeChart使用大數字作爲值
- 2. JFreeChart最大縮小
- 3. JFreeChart內插值
- 4. 顯示JFreeChart值
- 5. JFreeChart:增加數據點的大小
- 6. jfreechart獲取當前TickUnit值
- 7. 的JFreeChart - 餅圖缺失值
- 8. 如何從StackedBarChart獲取最大Y值(jFreeChart)
- 9. 如何設置直方圖JFreeChart YAxis的最大值?
- 10. 在JFreeChart中將圖表大小設置爲固定值
- 11. JfreeChart XYPlot在放大/縮小後凍結
- 12. 更改字體大小爲jfreechart的
- 13. java jfreechart庫泡沫大小問題
- 14. JPanel中可調整大小的JFreeChart
- 15. 如何更改一個JFreeChart的大小
- 16. ChartPanel不符合JPanel的大小(JFreeChart)
- 17. JFreeChart在y軸顯示負數時更改大小
- 18. 在JFreeChart中顯示巨大的數據集
- 19. JFreeChart - 數據集與系列?
- 20. JFreeChart PeriodAxis:29分鐘分數
- 21. JFreechart - 獲取當前顯示的數據集的最小值和最大值以自動調整y軸
- 22. JFreeChart&Image
- 23. ScatterPlotDemo-JfreeChart
- 24. JFreechart SeriesException
- 25. JFreeChart Margin
- 26. JFreeChart /圖表庫 - 值範圍選擇
- 27. 初始化JFreeChart範圍軸值
- 28. JFreechart - 想要自定義Y軸值
- 29. 在JFreeChart條形圖中垂直對齊數據值
- 30. JFreeChart TimeSeries Chart刪除沒有價值的天數