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

public class HeatmapSeries

  1. Object
  2. Series
  3. HeatmapSeries

A heatmap: a grid of cells coloured by value. Column c sits at x = c and row r at y = r, so pair it with a CategoryAxis on each axis to name the columns and rows.

Chart chart = new Chart();
double[][] values = {{3, 8, 5}, {6, 9, 4}, {2, 7, 8}};
chart.setXAxis(new CategoryAxis(Axis.BOTTOM, "Mon", "Tue", "Wed"));
chart.setYAxis(new CategoryAxis(Axis.LEFT, "Morning", "Noon", "Evening"));
chart.addSeries(new HeatmapSeries("Visits").setMatrix(values));

A heatmap

Constructors

public HeatmapSeries(String name)Creates an empty heatmap.

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 HeatmapSeries setMatrix(double[][] values)Replaces the values, animated.
public double getValue(int row, int column)The value of a cell.
public int getRows()The number of rows.
public int getColumns()The number of columns.
public HeatmapSeries setColorScale(ColorScale scale)The colour scale; by default a sequential scale of the series colour.
public HeatmapSeries setScaleRange(double min, double max)Fixes the values mapped to the ends of the scale instead of the data’s extent.
public double[] getValueRange()The range of values the colour scale spans: the fixed range when one is set, otherwise the smallest and largest value present.
public int cellId(int row, int column)The hit point id of a cell, row * getColumns() + column, which never aliases however wide the matrix is.
public double[] getXBounds()The extent of the data along x, {min, max}, or null when empty or not cartesian.
public double[] getXBoundsWithin(double maxX)The extent along x of the data at or below maxX, {min, max}, or null when none is.
public double[] getYBounds()The extent of the data along y, {min, max}, or null when empty or not cartesian.
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 void paintLegendSymbol(Graphics g, int x, int y, int size)Paints the legend swatch.
public int getPointCount()Every cell is a point, numbered row by row as cellId(row, column), so a selection or a tooltip survives a repaint and Chart.select can name a cell.
public ChartPoint getPoint(ChartContext ctx, int index)The point at index for a shared tooltip, or null.
public ChartPoint hitTest(ChartContext ctx, int x, int y, int radius)Finds the data point nearest a screen position.
public String formatValue(ChartContext ctx, double value)Formats a value for a label or tooltip.
public String formatTooltip(ChartContext ctx, ChartPoint p)The tooltip row for a point: the series or point name and its formatted value.
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

HeatmapSeries

public HeatmapSeries(String name)
Creates an empty heatmap.

Parameters

name String
the series name

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.

setMatrix

public HeatmapSeries setMatrix(double[][] values)
Replaces the values, animated.

Parameters

values double[][]
values[row][column]; NaN leaves a cell empty

Returns

this series

getValue

public double getValue(int row, int column)
The value of a cell.

getRows

public int getRows()
The number of rows.

getColumns

public int getColumns()
The number of columns.

setColorScale

public HeatmapSeries setColorScale(ColorScale scale)
The colour scale; by default a sequential scale of the series colour.

Parameters

scale ColorScale
the scale

Returns

this series

setScaleRange

public HeatmapSeries setScaleRange(double min, double max)
Fixes the values mapped to the ends of the scale instead of the data’s extent.

Parameters

min double
the value at the low end
max double
the value at the high end

Returns

this series

getValueRange

public double[] getValueRange()
The range of values the colour scale spans: the fixed range when one is set, otherwise the smallest and largest value present. A matrix with no values at all answers {0, 1}.

Returns

a new {min, max} array

cellId

public int cellId(int row, int column)
The hit point id of a cell, row * getColumns() + column, which never aliases however wide the matrix is.

Parameters

row int
the row
column int
the column

Returns

the id hitTest gives that cell’s point

getXBounds

public double[] getXBounds()
The extent of the data along x, {min, max}, or null when empty or not cartesian.

getXBoundsWithin

public double[] getXBoundsWithin(double maxX)
The extent along x of the data at or below maxX, {min, max}, or null when none is. A category axis with no labels asks for this to leave a far outlier out of its bands.

Parameters

maxX double
the largest x that counts

Returns

the bounds of the points that count, or null

getYBounds

public double[] getYBounds()
The extent of the data along y, {min, max}, or null when empty or not cartesian.

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

paintLegendSymbol

public void paintLegendSymbol(Graphics g, int x, int y, int size)
Paints the legend swatch.

Parameters

g Graphics
graphics
x int
swatch left
y int
swatch top
size int
swatch size

getPointCount

public int getPointCount()
Every cell is a point, numbered row by row as cellId(row, column), so a selection or a tooltip survives a repaint and Chart.select can name a cell.

getPoint

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

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

formatValue

public String formatValue(ChartContext ctx, double value)
Formats a value for a label or tooltip.

formatTooltip

public String formatTooltip(ChartContext ctx, ChartPoint p)
The tooltip row for a point: the series or point name and its formatted value. Series with several values per point (open/high/low/close, ranges, box plots) override this.

Parameters

ctx ChartContext
the last paint context
p ChartPoint
the point

Returns

one line of text

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