Class AxisLabels

    • Constructor Detail

      • AxisLabels

        public AxisLabels()
    • Method Detail

      • getAlign

        public String getAlign()
        Returns what part of the string the given position is anchored to. Can be one of left, center or right.

        Defaults: center.

      • setAlign

        public void setAlign​(String align)
        Sets what part of the string the given position is anchored to. Can be one of left, center or right.

        Defaults: center.

      • getAutoRotation

        public List<Number> getAutoRotation()
        For horizontal axes, the allowed degrees of label rotation to prevent overlapping labels. If there is enough space, labels are not rotated. As the chart gets narrower, it will start rotating the labels -45 degrees, then remove every second label and try again with rotations 0 and -45 etc.

        Defaults to [-45].

        Since:
        2.1.0
      • setAutoRotation

        public void setAutoRotation​(List<Number> autoRotation)
        Set the list of rotation degrees for horizontal axis labels. This list of degrees define all the possible rotation angles.
        Parameters:
        autoRotation -
        Since:
        2.1.0
        See Also:
        getAutoRotation()
      • setAutoRotation

        public void setAutoRotation​(Number... autoRotation)
        Set one or many rotation degrees for horizontal axis labels.
        Parameters:
        autoRotation -
        Since:
        2.1.0
        See Also:
        setAutoRotation(List)
      • getAutoRotationLimit

        public Number getAutoRotationLimit()
        When each category width is more than this many pixels, we don't apply auto rotation. Instead, we lay out the axis label with word wrap. A lower limit makes sense when the label contains multiple short words that don't extend the available horizontal space for each label.

        Defaults to 80.

        Returns:
        threshold where auto rotation starts to apply
        Since:
        2.1.0
      • setAutoRotationLimit

        public void setAutoRotationLimit​(Number autoRotationLimit)
        Set the width limit (in pixels) where auto rotation should stop being applied.
        Parameters:
        autoRotationLimit -
        Since:
        2.1.0
        See Also:
        getAutoRotationLimit()
      • getDistance

        public Number getDistance()
        Returns the distance of axis labels for Gauge chart type only.

        Default: 15

      • setDistance

        public void setDistance​(Number distance)
        Sets the distance of axis labels for Gauge chart type only.
      • isEnabled

        public boolean isEnabled()
        Returns whether to enable or disable the axis labels.

        Default: true.

      • setEnabled

        public void setEnabled​(boolean enabled)
        Sets whether to enable or disable the axis labels.
      • getFormat

        public String getFormat()
        Returns a format string for the axis label.

        Default: {value}.

      • setFormat

        public void setFormat​(String format)
        Sets a format string for the axis label.
      • getFormatter

        public org.zkoss.json.JavaScriptValue getFormatter()
        Callback JavaScript function to format the label. The value is given by "this.value". Additional properties for this are "axis", "chart", "isFirst" and "isLast".

        Default:

        function() { return this.value; }
        Since:
        2.1.0
      • setFormatter

        public void setFormatter​(org.zkoss.json.JavaScriptValue formatter)
        Parameters:
        formatter -
        Since:
        2.1.0
        See Also:
        getFormatter()
      • getMaxStaggerLines

        @Deprecated
        public Number getMaxStaggerLines()
        Deprecated.
        Returns the maximum lines of the to add to automatically avoid overlapping X labels. When staggerLines is not set, maxStaggerLines defines how many lines the axis is allowed to add to automatically avoid overlapping X labels. Set to 1 to disable overlap detection.

        Default: 5.

      • setMaxStaggerLines

        @Deprecated
        public void setMaxStaggerLines​(Number maxStaggerLines)
        Deprecated.
        Sets the maximum lines of the to add to automatically avoid overlapping X labels. When staggerLines is not set, maxStaggerLines defines how many lines the axis is allowed to add to automatically avoid overlapping X labels. Set to 1 to disable overlap detection.
      • getOverflow

        @Deprecated
        public String getOverflow()
        Deprecated.
        Returns how to handle overflowing labels on horizontal axis. Can be undefined or "justify". If "justify", labels will not render outside the plot area. If there is room to move it, it will be aligned to the edge, else it will be removed.

        Default: null.

      • setOverflow

        @Deprecated
        public void setOverflow​(String overflow)
        Deprecated.
        Sets how to handle overflowing labels on horizontal axis. Can be undefined or "justify". If "justify", labels will not render outside the plot area. If there is room to move it, it will be aligned to the edge, else it will be removed.
        Parameters:
        overflow - how to handle overflowing labels on horizontal axis
      • getPadding

        public Number getPadding()
        The pixel padding for axis labels, to ensure white space between them.

        Defaults to 5.

        Returns:
        the padding size in pixels
        Since:
        2.1.0
      • setPadding

        public void setPadding​(Number padding)
        Set the pixel padding for axis labels
        Parameters:
        padding -
        Since:
        2.1.0
        See Also:
        getPadding()
      • getPosition3D

        public String getPosition3D()
        Returns how the labels are be repositioned according to the 3D chart orientation.
        • 'offset': Maintain a fixed horizontal/vertical distance from the tick marks, despite the chart orientation. This is the backwards compatible behavior, and causes skewing of X and Z axes.
        • 'chart': Preserve 3D position relative to the chart. This looks nice, but hard to read if the text isn't forward-facing.
        • 'flap': Rotated text along the axis to compensate for the chart orientation. This tries to maintain text as legible as possible on all orientations.
        • 'ortho': Rotated text along the axis direction so that the labels are orthogonal to the axis. This is very similar to 'flap', but prevents skewing the labels (X and Y scaling are still present).
        Default: "offset"
        Since:
        7.2.1.0
      • setPosition3D

        public void setPosition3D​(String position3D)
        Sets how the labels are be repositioned according to the 3D chart orientation.
        • 'offset': Maintain a fixed horizontal/vertical distance from the tick marks, despite the chart orientation. This is the backwards compatible behavior, and causes skewing of X and Z axes.
        • 'chart': Preserve 3D position relative to the chart. This looks nice, but hard to read if the text isn't forward-facing.
        • 'flap': Rotated text along the axis to compensate for the chart orientation. This tries to maintain text as legible as possible on all orientations.
        • 'ortho': Rotated text along the axis direction so that the labels are orthogonal to the axis. This is very similar to 'flap', but prevents skewing the labels (X and Y scaling are still present).
        Since:
        7.2.1.0
      • isReserveSpace

        public boolean isReserveSpace()
        Returns whether to reserve space for the labels. By default, space is reserved for the labels in these cases:
        • On all horizontal axes.
        • On vertical axes if label.align is right on a left-side axis or left on a right-side axis.
        • On vertical axes if label.align is center.
        This can be turned off when for example the labels are rendered inside the plot area instead of outside. Default: true
        Since:
        7.2.1.0
      • setReserveSpace

        public void setReserveSpace​(boolean reserveSpace)
        Sets whether to reserve space for the labels. By default, space is reserved for the labels in these cases:
        • On all horizontal axes.
        • On vertical axes if label.align is right on a left-side axis or left on a right-side axis.
        • On vertical axes if label.align is center.
        This can be turned off when for example the labels are rendered inside the plot area instead of outside.
        Since:
        7.2.1.0
      • getRotation

        public Object getRotation()
        Returns rotation of the labels in degrees.

        Default: null.

      • setRotation

        public void setRotation​(Number rotation)
        Sets rotation of the labels in degrees.
        Parameters:
        rotation - rotation of the labels in degrees
      • setRotation

        public void setRotation​(String rotation)
        Sets rotation of the labels in degrees or auto.
        Parameters:
        rotation - rotation of the labels in degrees
      • isSkew3D

        public boolean isSkew3D()
        If enabled, the axis labels will skewed to follow the perspective. This will fix overlapping labels and titles, but texts become less legible due to the distortion. The final appearance depends heavily on labels.position3d.

        Default: false

        Since:
        7.2.1.0
      • setSkew3D

        public void setSkew3D​(boolean skew3D)
        If enabled, the axis labels will skewed to follow the perspective. This will fix overlapping labels and titles, but texts become less legible due to the distortion. The final appearance depends heavily on labels.position3d.
        Since:
        7.2.1.0
      • getStaggerLines

        public Number getStaggerLines()
        Returns the number of lines to spread the labels over to make room or tighter labels.

        Default: 0

        Returns:
        staggerLines the number of lines to spread the labels
      • setStaggerLines

        public void setStaggerLines​(Number staggerLines)
        Sets the number of lines to spread the labels over to make room or tighter labels.
      • getStep

        public Number getStep()
        Returns to show only every n'th label on the axis, set the step to n. Setting the step to 2 shows every other label.

        By default, on a vertical axis, the step is calculated automatically to avoid overlap. To prevent this, set it to 1. This usually only happens on a category axis, and is often a sign that you have chosen the wrong axis type. Read more at Axis docs => What axis should I use?

        Default: null.

      • setStep

        public void setStep​(Number step)
        Sets to show only every n'th label on the axis, set the step to n. Setting the step to 2 shows every other label.

        By default, on a vertical axis, the step is calculated automatically to avoid overlap. To prevent this, set it to 1. This usually only happens on a category axis, and is often a sign that you have chosen the wrong axis type. Read more at Axis docs => What axis should I use?

      • getStyle

        public <K,​V> Map<K,​V> getStyle()
        Returns CSS styles for the label. When labels are rotated they are rendered using vector graphic techniques and not all styles are applicable.

        Default:

         color: #6D869F; fontWeight: bold;
         
        Type Parameters:
        K - type for the key

        if style was set using setStyle(String), type will be String

        if style was set using setStyle(Map), type will be the same as the type from the key of the map

        if style was not set, default style will be applied, and type will be String

        V - type for the value

        if style was set using setStyle(String), type will be String

        if style was set using setStyle(Map), type will be the same as the type from the key of the map

        if style was not set, default style will be applied, and type will be String

      • setStyle

        public void setStyle​(String style)
        Sets CSS styles for the label. When labels are rotated they are rendered using vector graphic techniques and not all styles are applicable.

        This method allows simple settings like

        
         label.setStyle("fontWeight: 'bold'; color: 'white'; textShadow: '0px 1px 2px black'");
         

        In the format of CSS key:value, and ";" separating multiple key:value pairs, if you have more a complex CSS styling, we recommend using setStyle(Map)

        Parameters:
        style - one or many CSS key:value pairs in a single line string format
      • setStyle

        public <K,​V> void setStyle​(Map<K,​V> style)
        Sets CSS styles for the label. When labels are rotated they are rendered using vector graphic techniques and not all styles are applicable.

        This method allows complex styling like:

         
         Map<String, Object> styles = new HashMap<String, Object>();
         styles.put("fill", "#E8E8EA");
         styles.put("stroke", "#6E6E78");
         styles.put("stroke-width", "1");
         styles.put("r", "0");
         Map<String, Object> states = new HashMap<String, Object>();
         Map<String, String> hover = new HashMap<String, String>();
         hover.put("fill", "#F4F4F6");
         hover.put("stroke", "#6E6E78");
         hover.put("stroke-width", "1");
         hover.put("r", "0");
         states.put("hover", hover);
         styles.put("states", states);
         Map<String, String> style = new HashMap<String, String>();
         style.put("color", "#4D5663");
         style.put("fontSize", "12px");
         style.put("fontFamily", "'Arial'");
         style.put("fontWeight", "normal");
         style.put("padding", "10px");
         styles.put("style", style);
         
        which will generate the final results like:
        
         {
             "fill": "#E8E8EA",
             "stroke": "#6E6E78",
             "stroke-width": "1",
             "r": "0",
             "states":
             {
                 "hover":
                 {
                     "fill": "#F4F4F6",
                     "stroke": "#6E6E78",
                     "stroke-width": "1",
                     "r": "0"
                 }
             },
             "style":
             {
                 "color": "#4D5663",
                 "fontSize": "12px",
                 "fontFamily": "'Arial'",
                 "fontWeight": "normal",
                 "padding": "10px"
             }
         }
         
        Type Parameters:
        K - Type for the key, usually String
        V - Type for the value, usually String. For nested maps, use Object or any other type.
        Parameters:
        style - the style object
      • isUseHTML

        public boolean isUseHTML()
        Returns whether to use HTML to render the labels.

        Default: false.

      • setUseHTML

        public void setUseHTML​(boolean useHTML)
        Sets whether to use HTML to render the labels.
      • getX

        public Number getX()
        Returns the x position offset of the label relative to the tick position on the axis.

        Default: 0

      • setX

        public void setX​(Number x)
        Sets the x position offset of the label relative to the tick position on the axis.

        Default: 0

      • getY

        public Number getY()
        Returns the y position offset of the label relative to the tick position on the axis.

        Default: 0

      • setY

        public void setY​(Number y)
        Sets the y position offset of the label relative to the tick position on the axis.

        Default: 0

      • getZIndex

        public Number getZIndex()
        Returns the Z index for the axis labels.

        Default: 7.

      • setZIndex

        public void setZIndex​(Number zIndex)
        Sets the Z index for the axis labels.