Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9265223
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T14:01:00+00:00 2026-06-18T14:01:00+00:00

As from this very good post here Logarithmic scale in Java FX 2 I

  • 0

As from this very good post here

Logarithmic scale in Java FX 2

I have changed this class to get log scale on Y axis, and it works fine. The only problem I have is that there are very few horizontal grid lines and scale always start ranges from 0 or near zero.

Here is what I get

enter image description here

I would like to have tick values grid also in the min and max range of my data serie, in this case min = 19,35 max = 20,35; as of now all 10 horizontal grid lines are all plotted outside this range.

How to accomplish this?

Thanks all, here is my log code for Y axis

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<Number> {

//Create our LogarithmicAxis class that extends ValueAxis<Number> 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<Number> calculateMinorTickMarks() {
    Number[] range = getRange();
    List<Number> 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 <= logUpperBound; i += 1) {
            for (double j = 0; j <= 10; j += (1. / minorTickMarkCount)) {
                double value = j * Math.pow(10, i);
                minorTickMarksPositions.add(value);
            }
        }
    }
    return minorTickMarksPositions;
}

//Then, the calculateTickValues method is used to calculate a list of all the data values for each tick mark in range, represented by the second parameter. The formula is the same than previously but here we want to display one tick each power of 10.
@Override
protected List<Number> calculateTickValues(double length, Object range) {
    List<Number> tickPositions = new ArrayList<Number>();
    if (range != null) {
        Number lowerBound = ((Number[]) range)[0];
        Number upperBound = ((Number[]) range)[1];
        double logLowerBound = Math.log10(lowerBound.doubleValue());
        double logUpperBound = Math.log10(upperBound.doubleValue());
        System.out.println("lower bound is: " + lowerBound.doubleValue());

        for (double i = logLowerBound; i <= logUpperBound; i += 1) {
            for (double j = 1; j <= 10; j++) {
                double value = (j * Math.pow(10, i));
                tickPositions.add(value);
            }
        }
    }
    return tickPositions;
}

//The getRange provides the current range of the axis. A basic implementation is to return an array of the lowerBound and upperBound properties defined into the ValueAxis class.
@Override
protected Number[] getRange() {
    return new Number[] { lowerBoundProperty().get(), upperBoundProperty().get() };
}

//The getTickMarkLabel is only used to convert the number value to a string that will be displayed under the tickMark. Here I choose to use a number formatter.
@Override
protected String getTickMarkLabel(Number value) {
    NumberFormat formatter = NumberFormat.getInstance();
    formatter.setMaximumIntegerDigits(6);
    formatter.setMinimumIntegerDigits(1);
    return formatter.format(value);
}

//The method setRange is used to update the range when data are added into the chart. There is two possibilities, the axis is animated or not. The simplest case is to set the lower and upper bound properties directly with the new values.
@Override    
protected void setRange(Object range, boolean animate) {
    if (range != null) {
        Number lowerBound = ((Number[]) range)[0];
        Number upperBound = ((Number[]) range)[1];
        try {
            validateBounds(lowerBound.doubleValue(), upperBound.doubleValue());
        } catch (IllegalLogarithmicRangeException e) {
        }

        lowerBoundProperty().set(lowerBound.doubleValue());
        upperBoundProperty().set(upperBound.doubleValue());
    }
}

//We are almost done but we forgot to override 2 important methods that are used to perform the matching between data and the axis (and the reverse).
@Override
public Number getValueForDisplay(double displayPosition) {
    double delta = logUpperBound.get() - logLowerBound.get();
    if (getSide().isVertical()) {
        return Math.pow(10, (((displayPosition - getHeight()) / -getHeight()) * delta) + logLowerBound.get());
    } else {
        return Math.pow(10, (((displayPosition / getWidth()) * delta) + logLowerBound.get()));
    }
}

@Override
public double getDisplayPosition(Number value) {
    double delta = logUpperBound.get() - logLowerBound.get();
    double deltaV = Math.log10(value.doubleValue()) - logLowerBound.get();
    if (getSide().isVertical()) {
        return (1. - ((deltaV) / delta)) * getHeight();
    } else {
        return ((deltaV) / delta) * getWidth();
    }
}

/**
 * Exception to be thrown when a bound value isn't supported by the logarithmic axis<br>
 *
 *
 * @author Kevin Senechal mailto: kevin.senechal@dooapp.com
 *
 */
public class IllegalLogarithmicRangeException extends Exception {
/**
 * @param string
 */
    public IllegalLogarithmicRangeException(String message) {
        super(message);
    }
}
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T14:01:01+00:00Added an answer on June 18, 2026 at 2:01 pm

    I think your problem is this:

        super(1, 100);
    

    From the documentation:

    Create a non-auto-ranging ValueAxis with the given upper & lower bound

    Try using a constructor without parameters, which will make the boundaries auto-ranging.

    You should end up with a constructor looking like this:

    public LogarithmicAxis() {
        // was: super(1, 100);
        super();
        bindLogBoundsToDefaultBounds();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this very simple sql statement: SELECT max_dose FROM psychotropes WHERE (patient_meds.psychotrope =
I have a very large NumPy array: a = np.array . From this array
I have this Javascript code I inherited from another developer. I am very new
I have a very simply query like this: SELECT users.id, COUNT(others.id) as c FROM
Starting from Android 3.2 I have this strange problem. It's very easy to reproduce:
I see a very good post here about what I am wanting to do,
This is very basic question from programming point of view but as I am
I got this code from someone and it works very well, I just want
I'm very new at this, but I need to create new tables from existing
From this post : I would first suggest that you optimize your dependentObservable (a.k.a.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.