Class Axis

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable
    Direct Known Subclasses:
    CategoryAxis, ValueAxis

    public abstract class Axis
    extends java.lang.Object
    implements java.lang.Cloneable, java.io.Serializable
    The base class for all axes in JFreeChart. Subclasses are divided into those that display values (ValueAxis) and those that display categories (CategoryAxis).
    See Also:
    Serialized Form
    • Constructor Detail

      • Axis

        protected Axis​(java.lang.String label)
        Constructs an axis, using default values where necessary.
        Parameters:
        label - the axis label (null permitted).
    • Method Detail

      • isVisible

        public boolean isVisible()
        Returns true if the axis is visible, and false otherwise.
        Returns:
        A boolean.
        See Also:
        setVisible(boolean)
      • setVisible

        public void setVisible​(boolean flag)
        Sets a flag that controls whether or not the axis is visible and sends an AxisChangeEvent to all registered listeners.
        Parameters:
        flag - the flag.
        See Also:
        isVisible()
      • getAttributedLabel

        public java.text.AttributedString getAttributedLabel()
        Returns the attributed label (the returned value is a copy, so modifying it will not impact the state of the axis). The default value is null.
        Returns:
        The attributed label (possibly null).
        Since:
        1.0.16
      • setAttributedLabel

        public void setAttributedLabel​(java.lang.String label)
        Sets the attributed label for the axis and sends an AxisChangeEvent to all registered listeners. This is a convenience method that converts the string into an AttributedString using the current font attributes.
        Parameters:
        label - the label (null permitted).
        Since:
        1.0.16
      • setAttributedLabel

        public void setAttributedLabel​(java.text.AttributedString label)
        Sets the attributed label for the axis and sends an AxisChangeEvent to all registered listeners.
        Parameters:
        label - the label (null permitted).
        Since:
        1.0.16
      • createAttributedLabel

        public java.text.AttributedString createAttributedLabel​(java.lang.String label)
        Creates and returns an AttributedString with the specified text and the labelFont and labelPaint applied as attributes.
        Parameters:
        label - the label (null permitted).
        Returns:
        An attributed string or null.
        Since:
        1.0.16
      • getLabelFont

        public java.awt.Font getLabelFont()
        Returns the font for the axis label.
        Returns:
        The font (never null).
        See Also:
        setLabelFont(Font)
      • setLabelFont

        public void setLabelFont​(java.awt.Font font)
        Sets the font for the axis label and sends an AxisChangeEvent to all registered listeners.
        Parameters:
        font - the font (null not permitted).
        See Also:
        getLabelFont()
      • getLabelPaint

        public java.awt.Paint getLabelPaint()
        Returns the color/shade used to draw the axis label.
        Returns:
        The paint (never null).
        See Also:
        setLabelPaint(Paint)
      • setLabelPaint

        public void setLabelPaint​(java.awt.Paint paint)
        Sets the paint used to draw the axis label and sends an AxisChangeEvent to all registered listeners.
        Parameters:
        paint - the paint (null not permitted).
        See Also:
        getLabelPaint()
      • getLabelInsets

        public org.jfree.ui.RectangleInsets getLabelInsets()
        Returns the insets for the label (that is, the amount of blank space that should be left around the label).
        Returns:
        The label insets (never null).
        See Also:
        setLabelInsets(RectangleInsets)
      • setLabelInsets

        public void setLabelInsets​(org.jfree.ui.RectangleInsets insets)
        Sets the insets for the axis label, and sends an AxisChangeEvent to all registered listeners.
        Parameters:
        insets - the insets (null not permitted).
        See Also:
        getLabelInsets()
      • setLabelInsets

        public void setLabelInsets​(org.jfree.ui.RectangleInsets insets,
                                   boolean notify)
        Sets the insets for the axis label, and sends an AxisChangeEvent to all registered listeners.
        Parameters:
        insets - the insets (null not permitted).
        notify - notify listeners?
        Since:
        1.0.10
      • setLabelAngle

        public void setLabelAngle​(double angle)
        Sets the angle for the label and sends an AxisChangeEvent to all registered listeners.
        Parameters:
        angle - the angle (in radians).
        See Also:
        getLabelAngle()
      • setLabelLocation

        public void setLabelLocation​(AxisLabelLocation location)
        Sets the axis label location and sends an AxisChangeEvent to all registered listeners.
        Parameters:
        location - the new location (null not permitted).
        Since:
        1.0.16
      • setAxisLinePaint

        public void setAxisLinePaint​(java.awt.Paint paint)
        Sets the paint used to draw the axis line and sends an AxisChangeEvent to all registered listeners.
        Parameters:
        paint - the paint (null not permitted).
        See Also:
        getAxisLinePaint()
      • setAxisLineStroke

        public void setAxisLineStroke​(java.awt.Stroke stroke)
        Sets the stroke used to draw the axis line and sends an AxisChangeEvent to all registered listeners.
        Parameters:
        stroke - the stroke (null not permitted).
        See Also:
        getAxisLineStroke()
      • isMinorTickMarksVisible

        public boolean isMinorTickMarksVisible()
        Returns the flag that indicates whether or not the minor tick marks are showing.
        Returns:
        The flag that indicates whether or not the minor tick marks are showing.
        Since:
        1.0.12
        See Also:
        setMinorTickMarksVisible(boolean)
      • setTickLabelPaint

        public void setTickLabelPaint​(java.awt.Paint paint)
        Sets the paint used to draw tick labels (if they are showing) and sends an AxisChangeEvent to all registered listeners.
        Parameters:
        paint - the paint (null not permitted).
        See Also:
        getTickLabelPaint()
      • setTickLabelInsets

        public void setTickLabelInsets​(org.jfree.ui.RectangleInsets insets)
        Sets the insets for the tick labels and sends an AxisChangeEvent to all registered listeners.
        Parameters:
        insets - the insets (null not permitted).
        See Also:
        getTickLabelInsets()
      • isTickMarksVisible

        public boolean isTickMarksVisible()
        Returns the flag that indicates whether or not the tick marks are showing.
        Returns:
        The flag that indicates whether or not the tick marks are showing.
        See Also:
        setTickMarksVisible(boolean)
      • setTickMarkStroke

        public void setTickMarkStroke​(java.awt.Stroke stroke)
        Sets the stroke used to draw tick marks and sends an AxisChangeEvent to all registered listeners.
        Parameters:
        stroke - the stroke (null not permitted).
        See Also:
        getTickMarkStroke()
      • setTickMarkPaint

        public void setTickMarkPaint​(java.awt.Paint paint)
        Sets the paint used to draw tick marks and sends an AxisChangeEvent to all registered listeners.
        Parameters:
        paint - the paint (null not permitted).
        See Also:
        getTickMarkPaint()
      • getPlot

        public Plot getPlot()
        Returns the plot that the axis is assigned to. This method will return null if the axis is not currently assigned to a plot.
        Returns:
        The plot that the axis is assigned to (possibly null).
        See Also:
        setPlot(Plot)
      • setPlot

        public void setPlot​(Plot plot)
        Sets a reference to the plot that the axis is assigned to.

        This method is used internally, you shouldn't need to call it yourself.

        Parameters:
        plot - the plot.
        See Also:
        getPlot()
      • setFixedDimension

        public void setFixedDimension​(double dimension)
        Sets the fixed dimension for the axis.

        This is used when combining more than one plot on a chart. In this case, there may be several axes that need to have the same height or width so that they are aligned. This method is used to fix a dimension for the axis (the context determines whether the dimension is horizontal or vertical).

        Parameters:
        dimension - the fixed dimension.
        See Also:
        getFixedDimension()
      • configure

        public abstract void configure()
        Configures the axis to work with the current plot. Override this method to perform any special processing (such as auto-rescaling).
      • reserveSpace

        public abstract AxisSpace reserveSpace​(java.awt.Graphics2D g2,
                                               Plot plot,
                                               java.awt.geom.Rectangle2D plotArea,
                                               org.jfree.ui.RectangleEdge edge,
                                               AxisSpace space)
        Estimates the space (height or width) required to draw the axis.
        Parameters:
        g2 - the graphics device.
        plot - the plot that the axis belongs to.
        plotArea - the area within which the plot (including axes) should be drawn.
        edge - the axis location.
        space - space already reserved.
        Returns:
        The space required to draw the axis (including pre-reserved space).
      • draw

        public abstract AxisState draw​(java.awt.Graphics2D g2,
                                       double cursor,
                                       java.awt.geom.Rectangle2D plotArea,
                                       java.awt.geom.Rectangle2D dataArea,
                                       org.jfree.ui.RectangleEdge edge,
                                       PlotRenderingInfo plotState)
        Draws the axis on a Java 2D graphics device (such as the screen or a printer).
        Parameters:
        g2 - the graphics device (null not permitted).
        cursor - the cursor location (determines where to draw the axis).
        plotArea - the area within which the axes and plot should be drawn.
        dataArea - the area within which the data should be drawn.
        edge - the axis location (null not permitted).
        plotState - collects information about the plot (null permitted).
        Returns:
        The axis state (never null).
      • refreshTicks

        public abstract java.util.List refreshTicks​(java.awt.Graphics2D g2,
                                                    AxisState state,
                                                    java.awt.geom.Rectangle2D dataArea,
                                                    org.jfree.ui.RectangleEdge edge)
        Calculates the positions of the ticks for the axis, storing the results in the tick list (ready for drawing).
        Parameters:
        g2 - the graphics device.
        state - the axis state.
        dataArea - the area inside the axes.
        edge - the edge on which the axis is located.
        Returns:
        The list of ticks.
      • createAndAddEntity

        protected void createAndAddEntity​(double cursor,
                                          AxisState state,
                                          java.awt.geom.Rectangle2D dataArea,
                                          org.jfree.ui.RectangleEdge edge,
                                          PlotRenderingInfo plotState)
        Created an entity for the axis.
        Parameters:
        cursor - the initial cursor value.
        state - the axis state after completion of the drawing with a possibly updated cursor position.
        dataArea - the data area.
        edge - the edge.
        plotState - the PlotRenderingInfo from which a reference to the entity collection can be obtained.
        Since:
        1.0.13
      • hasListener

        public boolean hasListener​(java.util.EventListener listener)
        Returns true if the specified object is registered with the dataset as a listener. Most applications won't need to call this method, it exists mainly for use by unit testing code.
        Parameters:
        listener - the listener.
        Returns:
        A boolean.
      • notifyListeners

        protected void notifyListeners​(AxisChangeEvent event)
        Notifies all registered listeners that the axis has changed. The AxisChangeEvent provides information about the change.
        Parameters:
        event - information about the change to the axis.
      • getLabelEnclosure

        protected java.awt.geom.Rectangle2D getLabelEnclosure​(java.awt.Graphics2D g2,
                                                              org.jfree.ui.RectangleEdge edge)
        Returns a rectangle that encloses the axis label. This is typically used for layout purposes (it gives the maximum dimensions of the label).
        Parameters:
        g2 - the graphics device.
        edge - the edge of the plot area along which the axis is measuring.
        Returns:
        The enclosing rectangle.
      • drawLabel

        protected AxisState drawLabel​(java.lang.String label,
                                      java.awt.Graphics2D g2,
                                      java.awt.geom.Rectangle2D plotArea,
                                      java.awt.geom.Rectangle2D dataArea,
                                      org.jfree.ui.RectangleEdge edge,
                                      AxisState state)
        Draws the axis label.
        Parameters:
        label - the label text.
        g2 - the graphics device.
        plotArea - the plot area.
        dataArea - the area inside the axes.
        edge - the location of the axis.
        state - the axis state (null not permitted).
        Returns:
        Information about the axis.
      • drawAttributedLabel

        protected AxisState drawAttributedLabel​(java.text.AttributedString label,
                                                java.awt.Graphics2D g2,
                                                java.awt.geom.Rectangle2D plotArea,
                                                java.awt.geom.Rectangle2D dataArea,
                                                org.jfree.ui.RectangleEdge edge,
                                                AxisState state)
        Draws the axis label.
        Parameters:
        label - the label text.
        g2 - the graphics device.
        plotArea - the plot area.
        dataArea - the area inside the axes.
        edge - the location of the axis.
        state - the axis state (null not permitted).
        Returns:
        Information about the axis.
        Since:
        1.0.16
      • drawAxisLine

        protected void drawAxisLine​(java.awt.Graphics2D g2,
                                    double cursor,
                                    java.awt.geom.Rectangle2D dataArea,
                                    org.jfree.ui.RectangleEdge edge)
        Draws an axis line at the current cursor position and edge.
        Parameters:
        g2 - the graphics device.
        cursor - the cursor position.
        dataArea - the data area.
        edge - the edge.
      • clone

        public java.lang.Object clone()
                               throws java.lang.CloneNotSupportedException
        Returns a clone of the axis.
        Overrides:
        clone in class java.lang.Object
        Returns:
        A clone.
        Throws:
        java.lang.CloneNotSupportedException - if some component of the axis does not support cloning.
      • equals

        public boolean equals​(java.lang.Object obj)
        Tests this axis for equality with another object.
        Overrides:
        equals in class java.lang.Object
        Parameters:
        obj - the object (null permitted).
        Returns:
        true or false.
      • hashCode

        public int hashCode()
        Returns a hash code for this instance.
        Overrides:
        hashCode in class java.lang.Object
        Returns:
        A hash code.