Class Axis<T>

Type Parameters:
T - the axis data type
All Implemented Interfaces:
Styleable, EventTarget
Direct Known Subclasses:
CategoryAxis, ValueAxis

public abstract class Axis<T> extends Region
Base class for all axes in JavaFX that represents an axis drawn on a chart area. It holds properties for axis auto ranging, ticks and labels along the axis.

Some examples of concrete subclasses include NumberAxis whose axis plots data in numbers and CategoryAxis whose values / ticks represent string categories along its axis.

Since:
JavaFX 2.0
  • Property Details

  • Constructor Details

    • Axis

      public Axis()
      Creates and initializes a new instance of the Axis class.
  • Method Details

    • getTickMarks

      public ObservableList<Axis.TickMark<T>> getTickMarks()
      Unmodifiable observable list of tickmarks, each TickMark directly representing a tickmark on this axis. This is updated whenever the displayed tickmarks changes.
      Returns:
      Unmodifiable observable list of TickMarks on this axis
    • getSide

      public final Side getSide()
      Gets the value of the side property.
      Property description:
      The side of the plot which this axis is being drawn on
      Returns:
      the value of the side property
      See Also:
    • setSide

      public final void setSide(Side value)
      Sets the value of the side property.
      Property description:
      The side of the plot which this axis is being drawn on
      Parameters:
      value - the value for the side property
      See Also:
    • sideProperty

      public final ObjectProperty<Side> sideProperty()
      The side of the plot which this axis is being drawn on
      Returns:
      the side property
      See Also:
    • getLabel

      public final String getLabel()
      Gets the value of the label property.
      Property description:
      The axis label
      Returns:
      the value of the label property
      See Also:
    • setLabel

      public final void setLabel(String value)
      Sets the value of the label property.
      Property description:
      The axis label
      Parameters:
      value - the value for the label property
      See Also:
    • labelProperty

      public final ObjectProperty<String> labelProperty()
      The axis label
      Returns:
      the label property
      See Also:
    • isTickMarkVisible

      public final boolean isTickMarkVisible()
      Gets the value of the tickMarkVisible property.
      Property description:
      true if tick marks should be displayed
      Returns:
      the value of the tickMarkVisible property
      See Also:
    • setTickMarkVisible

      public final void setTickMarkVisible(boolean value)
      Sets the value of the tickMarkVisible property.
      Property description:
      true if tick marks should be displayed
      Parameters:
      value - the value for the tickMarkVisible property
      See Also:
    • tickMarkVisibleProperty

      public final BooleanProperty tickMarkVisibleProperty()
      true if tick marks should be displayed
      Returns:
      the tickMarkVisible property
      See Also:
    • isTickLabelsVisible

      public final boolean isTickLabelsVisible()
      Gets the value of the tickLabelsVisible property.
      Property description:
      true if tick mark labels should be displayed
      Returns:
      the value of the tickLabelsVisible property
      See Also:
    • setTickLabelsVisible

      public final void setTickLabelsVisible(boolean value)
      Sets the value of the tickLabelsVisible property.
      Property description:
      true if tick mark labels should be displayed
      Parameters:
      value - the value for the tickLabelsVisible property
      See Also:
    • tickLabelsVisibleProperty

      public final BooleanProperty tickLabelsVisibleProperty()
      true if tick mark labels should be displayed
      Returns:
      the tickLabelsVisible property
      See Also:
    • getTickLength

      public final double getTickLength()
      Gets the value of the tickLength property.
      Property description:
      The length of tick mark lines
      Returns:
      the value of the tickLength property
      See Also:
    • setTickLength

      public final void setTickLength(double value)
      Sets the value of the tickLength property.
      Property description:
      The length of tick mark lines
      Parameters:
      value - the value for the tickLength property
      See Also:
    • tickLengthProperty

      public final DoubleProperty tickLengthProperty()
      The length of tick mark lines
      Returns:
      the tickLength property
      See Also:
    • isAutoRanging

      public final boolean isAutoRanging()
      Gets the value of the autoRanging property.
      Property description:
      This is true when the axis determines its range from the data automatically
      Returns:
      the value of the autoRanging property
      See Also:
    • setAutoRanging

      public final void setAutoRanging(boolean value)
      Sets the value of the autoRanging property.
      Property description:
      This is true when the axis determines its range from the data automatically
      Parameters:
      value - the value for the autoRanging property
      See Also:
    • autoRangingProperty

      public final BooleanProperty autoRangingProperty()
      This is true when the axis determines its range from the data automatically
      Returns:
      the autoRanging property
      See Also:
    • getTickLabelFont

      public final Font getTickLabelFont()
      Gets the value of the tickLabelFont property.
      Property description:
      The font for all tick labels
      Returns:
      the value of the tickLabelFont property
      See Also:
    • setTickLabelFont

      public final void setTickLabelFont(Font value)
      Sets the value of the tickLabelFont property.
      Property description:
      The font for all tick labels
      Parameters:
      value - the value for the tickLabelFont property
      See Also:
    • tickLabelFontProperty

      public final ObjectProperty<Font> tickLabelFontProperty()
      The font for all tick labels
      Returns:
      the tickLabelFont property
      See Also:
    • getTickLabelFill

      public final Paint getTickLabelFill()
      Gets the value of the tickLabelFill property.
      Property description:
      The fill for all tick labels
      Returns:
      the value of the tickLabelFill property
      See Also:
    • setTickLabelFill

      public final void setTickLabelFill(Paint value)
      Sets the value of the tickLabelFill property.
      Property description:
      The fill for all tick labels
      Parameters:
      value - the value for the tickLabelFill property
      See Also:
    • tickLabelFillProperty

      public final ObjectProperty<Paint> tickLabelFillProperty()
      The fill for all tick labels
      Returns:
      the tickLabelFill property
      See Also:
    • getTickLabelGap

      public final double getTickLabelGap()
      Gets the value of the tickLabelGap property.
      Property description:
      The gap between tick labels and the tick mark lines
      Returns:
      the value of the tickLabelGap property
      See Also:
    • setTickLabelGap

      public final void setTickLabelGap(double value)
      Sets the value of the tickLabelGap property.
      Property description:
      The gap between tick labels and the tick mark lines
      Parameters:
      value - the value for the tickLabelGap property
      See Also:
    • tickLabelGapProperty

      public final DoubleProperty tickLabelGapProperty()
      The gap between tick labels and the tick mark lines
      Returns:
      the tickLabelGap property
      See Also:
    • getAnimated

      public final boolean getAnimated()
      Indicates whether the changes to axis range will be animated or not.
      Returns:
      true if axis range changes will be animated and false otherwise
    • setAnimated

      public final void setAnimated(boolean value)
      Sets the value of the animated property.
      Property description:
      When true any changes to the axis and its range will be animated.
      Parameters:
      value - the value for the animated property
      See Also:
    • animatedProperty

      public final BooleanProperty animatedProperty()
      When true any changes to the axis and its range will be animated.
      Returns:
      the animated property
      See Also:
    • getTickLabelRotation

      public final double getTickLabelRotation()
      Gets the value of the tickLabelRotation property.
      Property description:
      Rotation in degrees of tick mark labels from their normal horizontal.
      Returns:
      the value of the tickLabelRotation property
      See Also:
    • setTickLabelRotation

      public final void setTickLabelRotation(double value)
      Sets the value of the tickLabelRotation property.
      Property description:
      Rotation in degrees of tick mark labels from their normal horizontal.
      Parameters:
      value - the value for the tickLabelRotation property
      See Also:
    • tickLabelRotationProperty

      public final DoubleProperty tickLabelRotationProperty()
      Rotation in degrees of tick mark labels from their normal horizontal.
      Returns:
      the tickLabelRotation property
      See Also:
    • isRangeValid

      protected final boolean isRangeValid()
      See if the current range is valid, if it is not then any range dependent calulcations need to redone on the next layout pass
      Returns:
      true if current range calculations are valid
    • invalidateRange

      protected final void invalidateRange()
      Mark the current range invalid, this will cause anything that depends on the range to be recalculated on the next layout.
    • shouldAnimate

      protected final boolean shouldAnimate()
      This is used to check if any given animation should run. It returns true if animation is enabled and the node is visible and in a scene.
      Returns:
      true if animations should happen
    • requestLayout

      public void requestLayout()
      We suppress requestLayout() calls here by doing nothing as we don't want changes to our children to cause layout. If you really need to request layout then call requestAxisLayout().
      Overrides:
      requestLayout in class Parent
    • requestAxisLayout

      public void requestAxisLayout()
      Request that the axis is laid out in the next layout pass. This replaces requestLayout() as it has been overridden to do nothing so that changes to children's bounds etc do not cause a layout. This was done as a optimization as the Axis knows the exact minimal set of changes that really need layout to be updated. So we only want to request layout then, not on any child change.
    • invalidateRange

      public void invalidateRange(List<T> data)
      Called when data has changed and the range may not be valid any more. This is only called by the chart if isAutoRanging() returns true. If we are auto ranging it will cause layout to be requested and auto ranging to happen on next layout pass.
      Parameters:
      data - The current set of all data that needs to be plotted on this axis
    • autoRange

      protected abstract Object autoRange(double length)
      This calculates the upper and lower bound based on the data provided to invalidateRange() method. This must not effect the state of the axis, changing any properties of the axis. Any results of the auto-ranging should be returned in the range object. This will we passed to setRange() if it has been decided to adopt this range for this axis.
      Parameters:
      length - The length of the axis in screen coordinates
      Returns:
      Range information, this is implementation dependent
    • setRange

      protected abstract void setRange(Object range, boolean animate)
      Called to set the current axis range to the given range. If isAnimating() is true then this method should animate the range to the new range.
      Parameters:
      range - A range object returned from autoRange()
      animate - If true animate the change in range
    • getRange

      protected abstract Object getRange()
      Called to get the current axis range.
      Returns:
      A range object that can be passed to setRange() and calculateTickValues()
    • getZeroPosition

      public abstract double getZeroPosition()
      Get the display position of the zero line along this axis.
      Returns:
      display position or Double.NaN if zero is not in current range;
    • getDisplayPosition

      public abstract double getDisplayPosition(T value)
      Get the display position along this axis for a given value. If the value is not in the current range, the returned value will be an extrapolation of the display position. If the value is not valid for this Axis and the axis cannot display such value in any range, Double.NaN is returned
      Parameters:
      value - The data value to work out display position for
      Returns:
      display position or Double.NaN if value not valid
    • getValueForDisplay

      public abstract T getValueForDisplay(double displayPosition)
      Get the data value for the given display position on this axis. If the axis is a CategoryAxis this will be the nearest value.
      Parameters:
      displayPosition - A pixel position on this axis
      Returns:
      the nearest data value to the given pixel position or null if not on axis;
    • isValueOnAxis

      public abstract boolean isValueOnAxis(T value)
      Checks if the given value is plottable on this axis
      Parameters:
      value - The value to check if its on axis
      Returns:
      true if the given value is plottable on this axis
    • toNumericValue

      public abstract double toNumericValue(T value)
      All axis values must be representable by some numeric value. This gets the numeric value for a given data value.
      Parameters:
      value - The data value to convert
      Returns:
      Numeric value for the given data value
    • toRealValue

      public abstract T toRealValue(double value)
      All axis values must be representable by some numeric value. This gets the data value for a given numeric value.
      Parameters:
      value - The numeric value to convert
      Returns:
      Data value for given numeric value
    • calculateTickValues

      protected abstract List<T> calculateTickValues(double length, Object range)
      Calculate a list of all the data values for each tick mark in range
      Parameters:
      length - The length of the axis in display units
      range - A range object returned from autoRange()
      Returns:
      A list of tick marks that fit along the axis if it was the given length
    • computePrefHeight

      protected double computePrefHeight(double width)
      Computes the preferred height of this axis for the given width. If axis orientation is horizontal, it takes into account the tick mark length, tick label gap and label height.
      Overrides:
      computePrefHeight in class Region
      Parameters:
      width - the width that should be used if preferred height depends on it
      Returns:
      the computed preferred width for this axis
    • computePrefWidth

      protected double computePrefWidth(double height)
      Computes the preferred width of this axis for the given height. If axis orientation is vertical, it takes into account the tick mark length, tick label gap and label height.
      Overrides:
      computePrefWidth in class Region
      Parameters:
      height - the height that should be used if preferred width depends on it
      Returns:
      the computed preferred width for this axis
    • tickMarksUpdated

      protected void tickMarksUpdated()
      Called during layout if the tickmarks have been updated, allowing subclasses to do anything they need to in reaction.
    • layoutChildren

      protected void layoutChildren()
      Invoked during the layout pass to layout this axis and all its content.
      Overrides:
      layoutChildren in class Parent
    • getTickMarkLabel

      protected abstract String getTickMarkLabel(T value)
      Get the string label name for a tick mark with the given value
      Parameters:
      value - The value to format into a tick label string
      Returns:
      A formatted string for the given value
    • measureTickMarkLabelSize

      protected final Dimension2D measureTickMarkLabelSize(String labelText, double rotation)
      Measure the size of the label for given tick mark value. This uses the font that is set for the tick marks
      Parameters:
      labelText - tick mark label text
      rotation - The text rotation
      Returns:
      size of tick mark label for given value
    • measureTickMarkSize

      protected final Dimension2D measureTickMarkSize(T value, double rotation)
      Measure the size of the label for given tick mark value. This uses the font that is set for the tick marks
      Parameters:
      value - tick mark value
      rotation - The text rotation
      Returns:
      size of tick mark label for given value
    • measureTickMarkSize

      protected Dimension2D measureTickMarkSize(T value, Object range)
      Measure the size of the label for given tick mark value. This uses the font that is set for the tick marks
      Parameters:
      value - tick mark value
      range - range to use during calculations
      Returns:
      size of tick mark label for given value
    • getClassCssMetaData

      public static List<CssMetaData<? extends Styleable,?>> getClassCssMetaData()
      Gets the CssMetaData associated with this class, which may include the CssMetaData of its superclasses.
      Returns:
      the CssMetaData
      Since:
      JavaFX 8.0
    • getCssMetaData

      public List<CssMetaData<? extends Styleable,?>> getCssMetaData()
      This method should delegate to Node.getClassCssMetaData() so that a Node's CssMetaData can be accessed without the need for reflection.
      Specified by:
      getCssMetaData in interface Styleable
      Overrides:
      getCssMetaData in class Region
      Returns:
      The CssMetaData associated with this node, which may include the CssMetaData of its superclasses.
      Since:
      JavaFX 8.0