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

public class PieSeries

  1. Object
  2. Series
  3. CategoricalSeries
  4. PieSeries

A pie or doughnut chart.

Labels sit outside the pie on leader lines and are spread vertically so that no two overlap; when the chart is too small for them, or a slice is too thin to point at, the label is left out and the legend and tooltip carry the name instead.

Chart chart = new Chart();
PieSeries pie = new PieSeries("Share");
pie.setData(new String[]{"Android", "iOS", "Other"}, new double[]{71, 28, 1});
pie.setInnerRadius(0.6f).setCenterText("2.1B");
chart.addSeries(pie);

A pie A doughnut

Fields

public static final int LABELS_OUTSIDE = 0Names and percentages outside the pie on leader lines.
public static final int LABELS_INSIDE = 1Percentages inside slices large enough to hold them.
public static final int LABELS_NONE = 2No labels; the legend and tooltip name the slices.

Constructors

public PieSeries(String name)Creates an empty pie.

Methods

public PieSeries setInnerRadius(float fraction)Makes it a doughnut.
public PieSeries setStartAngle(double deg)Where the first slice starts.
public PieSeries setLabelMode(int mode)Chooses where labels go.
public PieSeries setCenterText(String text)Text shown in the hole of a doughnut, usually the total.
public PieSeries setPadAngle(float deg)The gap between slices.
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 ChartPoint getPoint(ChartContext ctx, int i)The point at index for a shared tooltip, or null.

Inherited methods

Field details

LABELS_OUTSIDE

public static final int LABELS_OUTSIDE = 0
Names and percentages outside the pie on leader lines.

LABELS_INSIDE

public static final int LABELS_INSIDE = 1
Percentages inside slices large enough to hold them.

LABELS_NONE

public static final int LABELS_NONE = 2
No labels; the legend and tooltip name the slices.

Constructor details

PieSeries

public PieSeries(String name)
Creates an empty pie.

Parameters

name String
the series name

Method details

setInnerRadius

public PieSeries setInnerRadius(float fraction)
Makes it a doughnut.

Parameters

fraction float
the hole’s radius as a fraction of the outer radius, 0 for a full pie

Returns

this series

setStartAngle

public PieSeries setStartAngle(double deg)
Where the first slice starts.

Parameters

deg double
degrees clockwise from twelve o’clock

Returns

this series

setLabelMode

public PieSeries setLabelMode(int mode)
Chooses where labels go.

Parameters

mode int
LABELS_OUTSIDE, LABELS_INSIDE or LABELS_NONE

Returns

this series

setCenterText

public PieSeries setCenterText(String text)
Text shown in the hole of a doughnut, usually the total.

Parameters

text String
the text, or null

Returns

this series

setPadAngle

public PieSeries setPadAngle(float deg)
The gap between slices.

Parameters

deg float
the gap in degrees, 0 for none

Returns

this series

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

getPoint

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