Class CategoryAxis

  • All Implemented Interfaces:
    Styleable, EventTarget

    public final class CategoryAxis
    extends Axis<String>
    A axis implementation that will works on string categories where each value as a unique category(tick mark) along the axis.
    Since:
    JavaFX 2.0
    • Constructor Detail

      • CategoryAxis

        public CategoryAxis()
        Create a auto-ranging category axis with an empty list of categories.
      • CategoryAxis

        public CategoryAxis​(ObservableList<String> categories)
        Create a category axis with the given categories. This will not auto-range but be fixed with the given categories.
        Parameters:
        categories - List of the categories for this axis
    • Method Detail

      • getStartMargin

        public final double getStartMargin()
        Gets the value of the property startMargin.
        Property description:
        The margin between the axis start and the first tick-mark
      • setStartMargin

        public final void setStartMargin​(double value)
        Sets the value of the property startMargin.
        Property description:
        The margin between the axis start and the first tick-mark
      • getEndMargin

        public final double getEndMargin()
        Gets the value of the property endMargin.
        Property description:
        The margin between the last tick mark and the axis end
      • setEndMargin

        public final void setEndMargin​(double value)
        Sets the value of the property endMargin.
        Property description:
        The margin between the last tick mark and the axis end
      • isGapStartAndEnd

        public final boolean isGapStartAndEnd()
        Gets the value of the property gapStartAndEnd.
        Property description:
        If this is true then half the space between ticks is left at the start and end
      • setGapStartAndEnd

        public final void setGapStartAndEnd​(boolean value)
        Sets the value of the property gapStartAndEnd.
        Property description:
        If this is true then half the space between ticks is left at the start and end
      • setCategories

        public final void setCategories​(ObservableList<String> value)
        The ordered list of categories plotted on this axis. This is set automatically based on the charts data if autoRanging is true. If the application sets the categories then auto ranging is turned off. If there is an attempt to add duplicate entry into this list, an IllegalArgumentException is thrown.
        Parameters:
        value - the ordered list of categories plotted on this axis
      • getCategories

        public final ObservableList<String> getCategories()
        Returns a ObservableList of categories plotted on this axis.
        Returns:
        ObservableList of categories for this axis.
      • getCategorySpacing

        public final double getCategorySpacing()
        Gets the value of the property categorySpacing.
        Property description:
        This is the gap between one category and the next along this axis
      • getRange

        protected Object getRange()
        Called to get the current axis range.
        Specified by:
        getRange in class Axis<String>
        Returns:
        A range object that can be passed to setRange() and calculateTickValues()
      • setRange

        protected 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.
        Specified by:
        setRange in class Axis<String>
        Parameters:
        range - A range object returned from autoRange()
        animate - If true animate the change in range
      • autoRange

        protected Object autoRange​(double length)
        This calculates the categories 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.
        Specified by:
        autoRange in class Axis<String>
        Parameters:
        length - The length of the axis in screen coordinates
        Returns:
        Range information, this is implementation dependent
      • calculateTickValues

        protected List<String> calculateTickValues​(double length,
                                                   Object range)
        Calculate a list of all the data values for each tick mark in range
        Specified by:
        calculateTickValues in class Axis<String>
        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
      • getTickMarkLabel

        protected String getTickMarkLabel​(String value)
        Get the string label name for a tick mark with the given value
        Specified by:
        getTickMarkLabel in class Axis<String>
        Parameters:
        value - The value to format into a tick label string
        Returns:
        A formatted string for the given value
      • measureTickMarkSize

        protected Dimension2D measureTickMarkSize​(String 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
        Overrides:
        measureTickMarkSize in class Axis<String>
        Parameters:
        value - tick mark value
        range - range to use during calculations
        Returns:
        size of tick mark label for given value
      • invalidateRange

        public void invalidateRange​(List<String> 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.
        Overrides:
        invalidateRange in class Axis<String>
        Parameters:
        data - The current set of all data that needs to be plotted on this axis
      • getDisplayPosition

        public double getDisplayPosition​(String value)
        Get the display position along this axis for a given value. If the value is not equal to any of the categories, Double.NaN is returned
        Specified by:
        getDisplayPosition in class Axis<String>
        Parameters:
        value - The data value to work out display position for
        Returns:
        display position or Double.NaN if value not one of the categories
      • getValueForDisplay

        public String 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.
        Specified by:
        getValueForDisplay in class Axis<String>
        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 boolean isValueOnAxis​(String value)
        Checks if the given value is plottable on this axis
        Specified by:
        isValueOnAxis in class Axis<String>
        Parameters:
        value - The value to check if its on axis
        Returns:
        true if the given value is plottable on this axis
      • toNumericValue

        public double toNumericValue​(String value)
        All axis values must be representable by some numeric value. This gets the numeric value for a given data value.
        Specified by:
        toNumericValue in class Axis<String>
        Parameters:
        value - The data value to convert
        Returns:
        Numeric value for the given data value
      • toRealValue

        public String toRealValue​(double value)
        All axis values must be representable by some numeric value. This gets the data value for a given numeric value.
        Specified by:
        toRealValue in class Axis<String>
        Parameters:
        value - The numeric value to convert
        Returns:
        Data value for given numeric value
      • getZeroPosition

        public double getZeroPosition()
        Get the display position of the zero line along this axis. As there is no concept of zero on a CategoryAxis this is always Double.NaN.
        Specified by:
        getZeroPosition in class Axis<String>
        Returns:
        always Double.NaN for CategoryAxis
      • getClassCssMetaData

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