Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.
public abstract class Axis
- Object
- 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 = 0 | Axis drawn below the plot. |
public static final int LEFT = 1 | Axis drawn left of the plot. |
public static final int RIGHT = 2 | Axis drawn right of the plot. |
public static final int TOP = 3 | Axis 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 = 0LEFT
public static final int LEFT = 1RIGHT
public static final int RIGHT = 2TOP
public static final int TOP = 3Constructor details
Axis
protected Axis(int position)Parameters
positionint- one of
BOTTOM,LEFT,RIGHTorTOP
Method details
getPosition
public int getPosition()setPosition
public Axis setPosition(int position)isVertical
public boolean isVertical()getTitle
public String getTitle()setTitle
public Axis setTitle(String title)isVisible
public boolean isVisible()setVisible
public Axis setVisible(boolean visible)isGridVisible
public boolean isGridVisible()setGridVisible
public Axis setGridVisible(boolean gridVisible)getFormatter
public ValueFormatter getFormatter()setFormatter
public Axis setFormatter(ValueFormatter formatter)setRange
public Axis setRange(Double min, Double max)Parameters
minDouble- the low end, or null to derive it from the data
maxDouble- the high end, or null to derive it from the data
Returns
isMinFixed
protected boolean isMinFixed()setRange pinned the low end, so adjustBounds must keep it as given.isMaxFixed
protected boolean isMaxFixed()setRange pinned the high end, so adjustBounds must keep it as given.setIncludeZero
public Axis setIncludeZero(boolean includeZero)isIncludeZero
public boolean isIncludeZero()setMaxZoom
public Axis setMaxZoom(double maxZoom)isZoomEnabled
public boolean isZoomEnabled()setZoomEnabled
public Axis setZoomEnabled(boolean zoomEnabled)setDataBounds
public void setDataBounds(double min, double max)Parameters
mindouble- smallest value of any visible series
maxdouble- largest value of any visible series
flatPad
protected double flatPad(double anchor)Parameters
anchordouble- the single value
Returns
adjustBounds
protected double[] adjustBounds(double min, double max)Parameters
mindouble- the raw minimum
maxdouble- the raw maximum
Returns
{min, max} to usegetDataMin
public double getDataMin()getDataMax
public double getDataMax()getVisibleMin
public double getVisibleMin()getVisibleMax
public double getVisibleMax()setVisibleRange
public void setVisibleRange(double min, double max)[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)restoreViewport
public void restoreViewport(double min, double max, boolean zoomed)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
mindouble- the visible minimum to restore
maxdouble- the visible maximum to restore
zoomedbooleanthe zoom flag to restore
This is an internal hook for
Chart(which lives in another package, so it has to be public); applications zoom withsetViewportandresetViewport. 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()isZoomed
public boolean isZoomed()zoom
public void zoom(double factor, double anchor)Parameters
factordouble- above 1 magnifies, below 1 shrinks
anchordouble- the normalized position (0..1 along the axis) that stays put
pan
public void pan(double normalizedDelta)forward
protected double forward(double value)log10 for a
logarithmic axis. Zoom, pan and normalization all work in this space.inverse
protected double inverse(double t)forward.toNormalized
public double toNormalized(double value)fromNormalized
public double fromNormalized(double n)toNormalized.ticks
public double[] ticks(int maxCount)Parameters
maxCountint- the most ticks the measured label size allows
Returns
format
public String format(double value, double step)Parameters
valuedouble- the value
stepdouble- neighbouring tick spacing, or 0
Returns
defaultFormat
protected String defaultFormat(double value, double step)formatNumber
public static String formatNumber(double value, int decimals)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
valuedouble- the number
decimalsint- decimal places, 0 or more