Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.
public class 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));
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
From Series
getName, setName, getColor, setColor, isVisible, setVisible, isSecondaryAxis, setSecondaryAxis, isShowValues, setShowValues, getValueFormatter, setValueFormatter, getChart, getSelectablePointCount, isPointCountFromLayout, getLegendEntryCount, getLegendEntryName, paintLegendEntrySymbol, isLegendEntryVisible, toggleLegendEntry, transitionEnded, handleTap, attached, detached, dataChanged, repaintChart, getVisibilityFraction, isGap, lerp
Constructor details
HeatmapSeries
public HeatmapSeries(String name)Creates an empty heatmap.
Parameters
nameString- 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
valuesdouble[][]values[row][column];NaNleaves 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
scaleColorScale- 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
mindouble- the value at the low end
maxdouble- 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} arraycellId
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
rowint- the row
columnint- the column
Returns
the id
hitTest gives that cell’s pointgetXBounds
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
maxXdouble- 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
ctxChartContext- 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
gGraphics- graphics
xint- swatch left
yint- swatch top
sizeint- 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
ctxChartContext- the frame the series was last painted in
xint- chart relative x
yint- chart relative y
radiusint- 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
ctxChartContext- the last paint context
pChartPoint- 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
rowsList<String[]>- the list to append rows to