JavaFX 2.x: логарифмическая шкала по оси Y

Как из этого очень хорошего поста здесь

Логарифмическая шкала в Java FX 2

Я изменил этот класс, чтобы получить масштаб журнала по оси Y, и он отлично работает. Единственная проблема, которую я имею, состоит в том, что очень мало горизонтальных линий сетки, и масштаб всегда начинает диапазоны от 0 или почти до нуля.

Вот что я получаю

Я хотел бы иметь сетку значений тиков также в диапазоне минимума и максимума моей серии данных, в этом случае min = 19,35 max = 20,35; на данный момент все 10 горизонтальных линий сетки построены за пределами этого диапазона.

Как это сделать?

Спасибо всем, вот мой лог-код для оси Y

import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.List;
import javafx.beans.binding.DoubleBinding;
import javafx.beans.property.DoubleProperty;
import javafx.beans.property.SimpleDoubleProperty;
import javafx.scene.chart.ValueAxis;

//http://blog.dooapp.com/logarithmic-scale-strikes-back-in-javafx-20        
public class LogarithmicAxis extends ValueAxis {

//Create our LogarithmicAxis class that extends ValueAxis and define two properties that will represent the log lower and upper bounds of our axis.     
private final DoubleProperty logUpperBound = new SimpleDoubleProperty();
private final DoubleProperty logLowerBound = new SimpleDoubleProperty();
//

//we bind our properties with the default bounds of the value axis. But before, we should verify the given range according to the mathematic logarithmic interval definition.
public LogarithmicAxis() {
    super(1, 100);
    bindLogBoundsToDefaultBounds();
}

public LogarithmicAxis(double lowerBound, double upperBound) {
    super(lowerBound, upperBound);
try {
    validateBounds(lowerBound, upperBound);
    bindLogBoundsToDefaultBounds();
} catch (IllegalLogarithmicRangeException e) {
    }
}

/**
 * Bind our logarithmic bounds with the super class bounds, consider the base 10 logarithmic scale.
 */
private void bindLogBoundsToDefaultBounds() {
    logLowerBound.bind(new DoubleBinding() {
        {
            super.bind(lowerBoundProperty());
        }

        @Override
        protected double computeValue() {
            return Math.log10(lowerBoundProperty().get());
        }
    });
    logUpperBound.bind(new DoubleBinding() {
        {
            super.bind(upperBoundProperty());
        }

        @Override
        protected double computeValue() {
            return Math.log10(upperBoundProperty().get());
        }
    });
}

/**
 * Validate the bounds by throwing an exception if the values are not conform to the mathematics log interval:
 * ]0,Double.MAX_VALUE]
 *
 * @param lowerBound
 * @param upperBound
 * @throws IllegalLogarithmicRangeException
 */
private void validateBounds(double lowerBound, double upperBound) throws IllegalLogarithmicRangeException {
    if (lowerBound < 0 || upperBound < 0 || lowerBound > upperBound) {
        throw new IllegalLogarithmicRangeException(
                "The logarithmic range should be include to ]0,Double.MAX_VALUE] and the lowerBound should be less than the upperBound");
    }
}

//Now we have to implement all abstract methods of the ValueAxis class.
//The first one, calculateMinorTickMarks is used to get the list of minor tick marks position that you want to display on the axis. You could find my definition below. It's based on the number of minor tick and the logarithmic formula.
@Override
protected List calculateMinorTickMarks() {
    Number[] range = getRange();
    List minorTickMarksPositions = new ArrayList();
    if (range != null) {

        Number lowerBound = range[0];
        Number upperBound = range[1];
        double logUpperBound = Math.log10(upperBound.doubleValue());
        double logLowerBound = Math.log10(lowerBound.doubleValue());

        int minorTickMarkCount = getMinorTickCount();

        for (double i = logLowerBound; i 

Ответы на вопрос(2)

Ваш ответ на вопрос