Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.

public abstract class Axis

  1. Object
  2. Axis

Known subtypesCategoryAxis, LogAxis, NumberAxis, SessionTimeAxis, TimeAxis

Base of every chart axis. An axis owns two ranges: the data range the chart computes from its series, and the visible range the user pans and zooms inside it.

Labels are never laid out by hand: the chart asks the axis for as many ticks as the measured label size allows, so labels on a small screen thin out instead of overlapping.

Fields

public static final int BOTTOM = 0Axis drawn below the plot.
public static final int LEFT = 1Axis drawn left of the plot.
public static final int RIGHT = 2Axis drawn right of the plot.
public static final int TOP = 3Axis drawn above the plot.

Constructors

protected Axis(int position)Creates an axis at the given position.

Methods

public int getPosition()The side of the plot this axis is drawn on.
public Axis setPosition(int position)Moves the axis to another side.
public boolean isVertical()True for an axis drawn left or right of the plot, which maps values vertically.
public String getTitle()The axis title, or null.
public Axis setTitle(String title)Sets the title drawn alongside the axis.
public boolean isVisible()Whether the axis line and labels are drawn.
public Axis setVisible(boolean visible)Hides or shows the axis; a hidden axis still maps values.
public boolean isGridVisible()Whether grid lines are drawn at the ticks.
public Axis setGridVisible(boolean gridVisible)Enables or disables grid lines at the ticks.
public ValueFormatter getFormatter()The formatter, or null for the axis’ default.
public Axis setFormatter(ValueFormatter formatter)Replaces how labels are formatted.
public Axis setRange(Double min, Double max)Pins the bounds instead of deriving them from the data; pass null to restore automatic.
protected boolean isMinFixed()True when setRange pinned the low end, so adjustBounds must keep it as given.
protected boolean isMaxFixed()True when setRange pinned the high end, so adjustBounds must keep it as given.
public Axis setIncludeZero(boolean includeZero)Forces zero into the automatic range, as a bar chart’s value axis needs.
public boolean isIncludeZero()True when zero is forced into the range.
public Axis setMaxZoom(double maxZoom)The largest magnification pan and zoom may reach, relative to the full data range.
public boolean isZoomEnabled()Whether gestures may zoom and pan this axis.
public Axis setZoomEnabled(boolean zoomEnabled)Allows or blocks zooming and panning along this axis.
public void setDataBounds(double min, double max)Called by the chart with the extent of the data on this axis.
protected double flatPad(double anchor)How far a range with a single value is padded on each side; 10% of the value, or 1 at zero.
protected double[] adjustBounds(double min, double max)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.
public double getDataMin()The low end of the data range.
public double getDataMax()The high end of the data range.
public double getVisibleMin()The low end of what is on screen.
public double getVisibleMax()The high end of what is on screen.
public void setVisibleRange(double min, double max)Shows exactly [min, max], clamped to the data range and the zoom limit.
public void setDisplayRange(double min, double max)Sets what is drawn for one frame of an animated transition, without clamping and without marking the axis as zoomed; the next data update replaces it.
public void restoreViewport(double min, double max, boolean zoomed)Puts back a viewport exactly as getVisibleMin(), getVisibleMax() and isZoomed() read it, without clamping or snapping; for undoing a temporary change such as an export, so the screen is left bit for bit as it was even mid-animation.
public void resetViewport()Returns to the full data range.
public boolean isZoomed()True when the user has zoomed in, so the visible range is narrower than the data.
public void zoom(double factor, double anchor)Zooms around a point.
public void pan(double normalizedDelta)Pans by a fraction of the visible span; positive moves toward larger values.
protected double forward(double value)Maps a value into the space the axis is linear in; the identity here, log10 for a logarithmic axis.
protected double inverse(double t)The inverse of forward.
public double toNormalized(double value)Maps a value to 0..1 across the visible range (outside 0..1 when off screen).
public double fromNormalized(double n)The inverse of toNormalized.
public double[] ticks(int maxCount)Ticks for the visible range.
public String format(double value, double step)Formats a tick or value with the custom formatter if set, else the default.
protected String defaultFormat(double value, double step)The axis’ built in formatting; numbers are grouped and localized.
public static String formatNumber(double value, int decimals)Formats value with exactly decimals decimal places through the localization manager.

Inherited methods

Field details

BOTTOM

public static final int BOTTOM = 0
Axis drawn below the plot.

LEFT

public static final int LEFT = 1
Axis drawn left of the plot.

TOP

public static final int TOP = 3
Axis drawn above the plot.

Constructor details

Axis

protected Axis(int position)
Creates an axis at the given position.

Parameters

position int
one of BOTTOM, LEFT, RIGHT or TOP

Method details

getPosition

public int getPosition()
The side of the plot this axis is drawn on.

setPosition

public Axis setPosition(int position)
Moves the axis to another side.

isVertical

public boolean isVertical()
True for an axis drawn left or right of the plot, which maps values vertically.

getTitle

public String getTitle()
The axis title, or null.

setTitle

public Axis setTitle(String title)
Sets the title drawn alongside the axis.

isVisible

public boolean isVisible()
Whether the axis line and labels are drawn.

setVisible

public Axis setVisible(boolean visible)
Hides or shows the axis; a hidden axis still maps values.

isGridVisible

public boolean isGridVisible()
Whether grid lines are drawn at the ticks.

setGridVisible

public Axis setGridVisible(boolean gridVisible)
Enables or disables grid lines at the ticks.

getFormatter

public ValueFormatter getFormatter()
The formatter, or null for the axis’ default.

setFormatter

public Axis setFormatter(ValueFormatter formatter)
Replaces how labels are formatted.

setRange

public Axis setRange(Double min, Double max)
Pins the bounds instead of deriving them from the data; pass null to restore automatic. Bounds given in the wrong order are taken as a range, and two equal bounds are widened by a pad on each side so the axis is never empty. A single bound pinned at the very end of the double range gives way by that pad when the free side has no room left.

Parameters

min Double
the low end, or null to derive it from the data
max Double
the high end, or null to derive it from the data

Returns

this axis

isMinFixed

protected boolean isMinFixed()
True when setRange pinned the low end, so adjustBounds must keep it as given.

isMaxFixed

protected boolean isMaxFixed()
True when setRange pinned the high end, so adjustBounds must keep it as given.

setIncludeZero

public Axis setIncludeZero(boolean includeZero)
Forces zero into the automatic range, as a bar chart’s value axis needs.

isIncludeZero

public boolean isIncludeZero()
True when zero is forced into the range.

setMaxZoom

public Axis setMaxZoom(double maxZoom)
The largest magnification pan and zoom may reach, relative to the full data range.

isZoomEnabled

public boolean isZoomEnabled()
Whether gestures may zoom and pan this axis.

setZoomEnabled

public Axis setZoomEnabled(boolean zoomEnabled)
Allows or blocks zooming and panning along this axis.

setDataBounds

public void setDataBounds(double min, double max)
Called by the chart with the extent of the data on this axis.

Parameters

min double
smallest value of any visible series
max double
largest value of any visible series

flatPad

protected double flatPad(double anchor)
How far a range with a single value is padded on each side; 10% of the value, or 1 at zero. A time axis overrides it, since 10% of an epoch timestamp is years.

Parameters

anchor double
the single value

Returns

the pad, positive

adjustBounds

protected double[] adjustBounds(double min, double max)
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 double
the raw minimum
max double
the raw maximum

Returns

{min, max} to use

getDataMin

public double getDataMin()
The low end of the data range.

getDataMax

public double getDataMax()
The high end of the data range.

getVisibleMin

public double getVisibleMin()
The low end of what is on screen.

getVisibleMax

public double getVisibleMax()
The high end of what is on screen.

setVisibleRange

public void setVisibleRange(double min, double max)
Shows exactly [min, max], clamped to the data range and the zoom limit. Showing the whole data range clears the zoom, so later data changes rescale the axis again.

setDisplayRange

public void setDisplayRange(double min, double max)
Sets what is drawn for one frame of an animated transition, without clamping and without marking the axis as zoomed; the next data update replaces it.

restoreViewport

public void restoreViewport(double min, double max, boolean zoomed)
Puts back a viewport exactly as getVisibleMin(), getVisibleMax() and isZoomed() read it, without clamping or snapping; for undoing a temporary change such as an export, so the screen is left bit for bit as it was even mid-animation.

Parameters

min double
the visible minimum to restore
max double
the visible maximum to restore
zoomed boolean

the zoom flag to restore

This is an internal hook for Chart (which lives in another package, so it has to be public); applications zoom with setViewport and resetViewport. A range that is not finite, or whose minimum exceeds its maximum, is ignored, so it can never put an axis into a state no other method allows.

resetViewport

public void resetViewport()
Returns to the full data range.

isZoomed

public boolean isZoomed()
True when the user has zoomed in, so the visible range is narrower than the data.

zoom

public void zoom(double factor, double anchor)
Zooms around a point.

Parameters

factor double
above 1 magnifies, below 1 shrinks
anchor double
the normalized position (0..1 along the axis) that stays put

pan

public void pan(double normalizedDelta)
Pans by a fraction of the visible span; positive moves toward larger values.

forward

protected double forward(double value)
Maps a value into the space the axis is linear in; the identity here, log10 for a logarithmic axis. Zoom, pan and normalization all work in this space.

inverse

protected double inverse(double t)
The inverse of forward.

toNormalized

public double toNormalized(double value)
Maps a value to 0..1 across the visible range (outside 0..1 when off screen).

fromNormalized

public double fromNormalized(double n)
The inverse of toNormalized.

ticks

public double[] ticks(int maxCount)
Ticks for the visible range.

Parameters

maxCount int
the most ticks the measured label size allows

Returns

ascending tick values

format

public String format(double value, double step)
Formats a tick or value with the custom formatter if set, else the default.

Parameters

value double
the value
step double
neighbouring tick spacing, or 0

Returns

the label

defaultFormat

protected String defaultFormat(double value, double step)
The axis’ built in formatting; numbers are grouped and localized.

formatNumber

public static String formatNumber(double value, int decimals)
Formats value with exactly decimals decimal places through the localization manager. Whole numbers print without a decimal point, which the double overload of L10NManager.format does not guarantee.

Parameters

value double
the number
decimals int
decimal places, 0 or more

Returns

the localized text