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

public class GaugeSeries

  1. Object
  2. Series
  3. GaugeSeries

A gauge: one value on a curved scale, with optional coloured bands such as green / amber / red zones. The needle or the filled arc animates to each new value.

GaugeSeries cpu = new GaugeSeries("CPU", 0, 100).setValue(72);
cpu.addBand(0, 60, 0x009E73).addBand(60, 85, 0xE69F00).addBand(85, 100, 0xD55E00);

A gauge

Constructors

public GaugeSeries(String name, double min, double max)Creates a gauge.

Methods

public boolean isCartesian()True for series drawn against x and y axes; false for pies, treemaps and other series that fill the plot themselves.
public GaugeSeries setValue(double v)Sets the value, animated from the current one.
public double getValue()The current value.
public GaugeSeries setRange(double min, double max)Changes the scale.
public double getRangeMin()The start of the scale.
public double getRangeMax()The end of the scale.
public GaugeSeries addBand(double from, double to, int rgb)Adds a coloured zone to the scale.
public GaugeSeries setSweep(double deg)The angle the scale spans; 180 is a semicircle, 240 the default, 360 a ring.
public GaugeSeries setNeedle(boolean n)Shows a needle over the bands instead of a filled arc.
public GaugeSeries setUnit(String unit)Text appended to the value, such as “%” or " km/h".
protected void captureTransitionStart()Records the values currently on screen as the start of the next transition.
protected void captureEntryStart()Records a zero baseline as the start of the entry animation.
public void paint(ChartContext ctx)Paints the series.
public ChartPoint hitTest(ChartContext ctx, int x, int y, int radius)Finds the data point nearest a screen position.
public int getPointCount()The number of points along x, for a shared tooltip; -1 when not index aligned.
public ChartPoint getPoint(ChartContext ctx, int index)The point at index for a shared tooltip, or null.
public void collectTableRows(List<String[]> rows)Adds this series’ data to an accessible table, one {series, item, value} row per point.

Inherited methods

Constructor details

GaugeSeries

public GaugeSeries(String name, double min, double max)
Creates a gauge.

Parameters

name String
the label under the value
min double
the start of the scale
max double
the end of the scale

Method details

isCartesian

public boolean isCartesian()
True for series drawn against x and y axes; false for pies, treemaps and other series that fill the plot themselves.

setValue

public GaugeSeries setValue(double v)
Sets the value, animated from the current one.

Parameters

v double
the new value, clamped to the scale

Returns

this series

getValue

public double getValue()
The current value.

setRange

public GaugeSeries setRange(double min, double max)
Changes the scale. Ends given in the wrong order are swapped, so setRange(100, 0) is the scale from 0 to 100.

Parameters

min double
the start of the scale
max double
the end of the scale

Returns

this series

getRangeMin

public double getRangeMin()
The start of the scale.

Returns

the smaller end

getRangeMax

public double getRangeMax()
The end of the scale.

Returns

the larger end

addBand

public GaugeSeries addBand(double from, double to, int rgb)
Adds a coloured zone to the scale.

Parameters

from double
where the zone starts
to double
where the zone ends
rgb int
its colour

Returns

this series

setSweep

public GaugeSeries setSweep(double deg)
The angle the scale spans; 180 is a semicircle, 240 the default, 360 a ring.

Parameters

deg double
the sweep in degrees

Returns

this series

setNeedle

public GaugeSeries setNeedle(boolean n)
Shows a needle over the bands instead of a filled arc.

Parameters

n boolean
true for a needle

Returns

this series

setUnit

public GaugeSeries setUnit(String unit)
Text appended to the value, such as “%” or " km/h".

Parameters

unit String
the suffix

Returns

this series

captureTransitionStart

protected void captureTransitionStart()
Records the values currently on screen as the start of the next transition. Called by the chart before data changes; a subclass with animated data overrides it.

captureEntryStart

protected void captureEntryStart()
Records a zero baseline as the start of the entry animation.

paint

public void paint(ChartContext ctx)
Paints the series.

Parameters

ctx ChartContext
the current frame: graphics, plot area, axes and animation progress

hitTest

public ChartPoint hitTest(ChartContext ctx, int x, int y, int radius)
Finds the data point nearest a screen position.

Parameters

ctx ChartContext
the frame the series was last painted in
x int
chart relative x
y int
chart relative y
radius int
how far from the point a touch may land and still hit it

Returns

the point, or null

getPointCount

public int getPointCount()
The number of points along x, for a shared tooltip; -1 when not index aligned.

getPoint

public ChartPoint getPoint(ChartContext ctx, int index)
The point at index for a shared tooltip, or null.

collectTableRows

public void collectTableRows(List<String[]> rows)
Adds this series’ data to an accessible table, one {series, item, value} row per point. Used by Chart.toTable() and the chart’s accessibility text.

Parameters

rows List<String[]>
the list to append rows to