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

public final class ChartElement

  1. Object
  2. SlideElement
  3. ChartElement

A chart on a slide: its data – categories, named series of values, colors – and its kind. It is drawn by com.codename1.ui.chart.Chart, so a slide’s chart looks like and animates like any other chart in the application, and toChart gives the live, interactive component for a slide show that wants one.

PPTX charts (c:chartSpace) and ODF charts are read into this model; a kind or option the model lacks falls back to the nearest kind.

Fields

public static final String COLUMN = "column"Vertical bars (OOXML’s column chart).
public static final String BAR = "bar"Horizontal bars.
public static final String LINE = "line"Lines.
public static final String AREA = "area"Filled areas under lines.
public static final String PIE = "pie"A pie of the first series.
public static final String DOUGHNUT = "doughnut"A pie with a hole.
public static final String SCATTER = "scatter"Points: the categories, read as numbers, are x and every series is y; see xValues().
public static final String RADAR = "radar"A radar (spider) chart.
public final String kindThe kind, one of the constants.
public final String titleThe title, or null.
public final boolean stackedTrue when bars or areas of different series stack.
public final boolean legendTrue when a legend is shown.

Constructors

public ChartElement(String id, String kind, float x, float y, float width, float height, String[] categories, String[] seriesNames, double[][] values)A chart.
public ChartElement(String id, String name, String kind, float x, float y, float width, float height, float rotation, String title, boolean stacked, boolean legend, String[] categories, String[] seriesNames, double[][] values, int[] colors)A chart with every property.

Methods

public double[] xValues()The x values of a scatter chart: its categories read as numbers, as PPTX’s xVal and ODF’s x range hold them, or 1, 2, 3…
public int categoryCount()The number of categories.
public String category(int i)A category label.
public int seriesCount()The number of series.
public String seriesName(int i)A series name.
public double[] values(int i)A copy of one series’ values.
public int seriesColor(int i)The color of a series, or -1 when the chart theme picks it.
public ChartElement withData(String[] cats, String[] names, double[][] data)This chart with other data.
public ChartElement withKind(String value)This chart as another kind.
public ChartElement withTitle(String value)This chart with a title.
public ChartElement withStacked(boolean value)This chart stacked or side by side.
public ChartElement withColors(int[] value)This chart with series colors.
public Chart toChart()A live Chart component showing this data.
public SlideElement withTransform(float nx, float ny, float nw, float nh, float rot, boolean fh, boolean fv)This element moved, resized, rotated or flipped.
public SlideElement withId(String value)This element with another id, for copies.
public String plainText()The text of the element for search, outlines and screen readers.
public boolean equals(Object o)Indicates whether some other object is “equal to” this one.
public int hashCode()Returns a hash code value for the object.

Inherited fields

Inherited methods

Field details

COLUMN

public static final String COLUMN = "column"
Vertical bars (OOXML’s column chart).

BAR

public static final String BAR = "bar"
Horizontal bars.

LINE

public static final String LINE = "line"
Lines.

AREA

public static final String AREA = "area"
Filled areas under lines.

PIE

public static final String PIE = "pie"
A pie of the first series.

DOUGHNUT

public static final String DOUGHNUT = "doughnut"
A pie with a hole.

SCATTER

public static final String SCATTER = "scatter"
Points: the categories, read as numbers, are x and every series is y; see xValues().

RADAR

public static final String RADAR = "radar"
A radar (spider) chart.

kind

public final String kind
The kind, one of the constants.

title

public final String title
The title, or null.

stacked

public final boolean stacked
True when bars or areas of different series stack.

legend

public final boolean legend
True when a legend is shown.

Constructor details

ChartElement

public ChartElement(String id, String kind, float x, float y, float width, float height, String[] categories, String[] seriesNames, double[][] values)
A chart.

Parameters

id String
the id
kind String
one of the kind constants
x float
left edge in points
y float
top edge
width float
width
height float
height
categories String[]
the category labels
seriesNames String[]
one name per series
values double[][]
one row of values per series, one value per category

ChartElement

public ChartElement(String id, String name, String kind, float x, float y, float width, float height, float rotation, String title, boolean stacked, boolean legend, String[] categories, String[] seriesNames, double[][] values, int[] colors)
A chart with every property.

Parameters

id String
the id
name String
a name, or null
kind String
one of the kind constants
x float
left edge
y float
top edge
width float
width
height float
height
rotation float
degrees clockwise
title String
the title, or null
stacked boolean
whether series stack
legend boolean
whether a legend shows
categories String[]
the category labels
seriesNames String[]
the series names
values double[][]
one row per series
colors int[]
one 0xRRGGBB per series, or null for the chart theme’s

Method details

xValues

public double[] xValues()
The x values of a scatter chart: its categories read as numbers, as PPTX’s xVal and ODF’s x range hold them, or 1, 2, 3… where a category is not a number.

Returns

one x value per category

categoryCount

public int categoryCount()
The number of categories.

Returns

the count

category

public String category(int i)
A category label.

Parameters

i int
the index

Returns

the label

seriesCount

public int seriesCount()
The number of series.

Returns

the count

seriesName

public String seriesName(int i)
A series name.

Parameters

i int
the series

Returns

the name

values

public double[] values(int i)
A copy of one series’ values.

Parameters

i int
the series

Returns

the values

seriesColor

public int seriesColor(int i)
The color of a series, or -1 when the chart theme picks it.

Parameters

i int
the series

Returns

0xRRGGBB or -1

withData

public ChartElement withData(String[] cats, String[] names, double[][] data)
This chart with other data.

Parameters

cats String[]
categories
names String[]
series names
data double[][]
one row per series

Returns

the chart

withKind

public ChartElement withKind(String value)
This chart as another kind.

Parameters

value String
one of the kind constants

Returns

the chart

withTitle

public ChartElement withTitle(String value)
This chart with a title.

Parameters

value String
the title, or null

Returns

the chart

withStacked

public ChartElement withStacked(boolean value)
This chart stacked or side by side.

Parameters

value boolean
true to stack

Returns

the chart

withColors

public ChartElement withColors(int[] value)
This chart with series colors.

Parameters

value int[]
0xRRGGBB per series, or null

Returns

the chart

toChart

public Chart toChart()
A live Chart component showing this data. Each call makes a new one; a slide show places it over the slide so the audience gets tooltips and the entrance animation.

Returns

the chart

withTransform

public SlideElement withTransform(float nx, float ny, float nw, float nh, float rot, boolean fh, boolean fv)
This element moved, resized, rotated or flipped.

Parameters

nx float
left edge
ny float
top edge
nw float
width
nh float
height
rot float
degrees clockwise
fh boolean
mirrored horizontally
fv boolean
mirrored vertically

Returns

the changed element

withId

public SlideElement withId(String value)
This element with another id, for copies.

Parameters

value String
the id

Returns

the element

plainText

public String plainText()
The text of the element for search, outlines and screen readers.

Returns

the text, empty when there is none

equals

public boolean equals(Object o)
Indicates whether some other object is “equal to” this one. The equals method implements an equivalence relation: It is reflexive: for any reference value x, x.equals(x) should return true. It is symmetric: for any reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true. It is transitive: for any reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true. It is consistent: for any reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the object is modified. For any non-null reference value x, x.equals(null) should return false. The equals method for class Object implements the most discriminating possible equivalence relation on objects; that is, for any reference values x and y, this method returns true if and only if x and y refer to the same object (x==y has the value true).

hashCode

public int hashCode()
Returns a hash code value for the object. This method is supported for the benefit of hashtables such as those provided by java.util.Hashtable. The general contract of hashCode is: Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application. If two objects are equal according to the equals(Object) method, then calling the hashCode method on each of the two objects must produce the same integer result. It is not required that if two objects are unequal according to the equals(java.lang.Object) method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hashtables. As much as is reasonably practical, the hashCode method defined by class Object does return distinct integers for distinct objects. (This is typically implemented by converting the internal address of the object into an integer, but this implementation technique is not required by the JavaTM programming language.)