Class CategoryAxis

java.lang.Object
com.codename1.ui.chart.axis.Axis
com.codename1.ui.chart.axis.CategoryAxis

public class CategoryAxis extends Axis

An axis of named, evenly spaced categories. Category i sits at value i, in the middle of its band, so bars and points line up with their label.

When labels do not fit side by side the chart first rotates them, then shows every n-th one, and finally truncates with an ellipsis; it never draws them over each other.

Long category names, rotated to fit

  • Constructor Details

    • CategoryAxis

      public CategoryAxis(int position, String... labels)

      Creates a category axis.

      Parameters
      • position: one of Axis.BOTTOM, Axis.LEFT, Axis.RIGHT or Axis.TOP

      • labels: the category names, in order

  • Method Details

    • setCategories

      public CategoryAxis setCategories(String... labels)
      Replaces the category names.
    • getCategoryCount

      public int getCategoryCount()
      The number of categories.
    • getCategory

      public String getCategory(int i)
      The name of category i, or an empty string out of range.
    • setDataBounds

      public void setDataBounds(double min, double max)
      Description copied from class: Axis

      Called by the chart with the extent of the data on this axis.

      Parameters
      • min: smallest value of any visible series

      • max: largest value of any visible series

      Overrides:
      setDataBounds in class Axis
    • getDataLimit

      public double getDataLimit()

      The largest x a data point may have and still open its own band; a point further out is an outlier the axis ignores.

      Returns

      the largest x that counts

    • adjustBounds

      protected double[] adjustBounds(double min, double max)
      Description copied from class: Axis

      Lets a subclass pad or round the automatic bounds; the default rounds a numeric range outward to the nearest nice step so the outermost grid lines sit on the plot edge.

      Parameters
      • min: the raw minimum

      • max: the raw maximum

      Returns

      {min, max} to use

      Overrides:
      adjustBounds in class Axis
    • ticks

      public double[] ticks(int maxCount)
      Description copied from class: Axis

      Ticks for the visible range.

      Parameters
      • maxCount: the most ticks the measured label size allows
      Returns

      ascending tick values

      Overrides:
      ticks in class Axis
    • defaultFormat

      protected String defaultFormat(double value, double step)
      Description copied from class: Axis
      The axis' built in formatting; numbers are grouped and localized.
      Overrides:
      defaultFormat in class Axis
    • getBandWidth

      public double getBandWidth()
      The width of one category band in normalized units, used to size bars.