Class HeatmapSeries

java.lang.Object
com.codename1.ui.chart.Series
com.codename1.ui.chart.series.HeatmapSeries

public class HeatmapSeries extends Series

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

  • Constructor Details

    • HeatmapSeries

      public HeatmapSeries(String name)

      Creates an empty heatmap.

      Parameters
      • name: the series name
  • Method Details

    • isCartesian

      public boolean isCartesian()
      Description copied from class: Series
      True for series drawn against x and y axes; false for pies, treemaps and other series that fill the plot themselves.
      Specified by:
      isCartesian in class Series
    • setMatrix

      public HeatmapSeries setMatrix(double[][] values)

      Replaces the values, animated.

      Parameters
      • values: 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: 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: the value at the low end

      • max: 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: the row

      • column: the column

      Returns

      the id hitTest gives that cell's point

    • getXBounds

      public double[] getXBounds()
      Description copied from class: Series
      The extent of the data along x, {min, max}, or null when empty or not cartesian.
      Overrides:
      getXBounds in class Series
    • getXBoundsWithin

      public double[] getXBoundsWithin(double maxX)
      Description copied from class: Series

      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: the largest x that counts
      Returns

      the bounds of the points that count, or null

      Overrides:
      getXBoundsWithin in class Series
    • getYBounds

      public double[] getYBounds()
      Description copied from class: Series
      The extent of the data along y, {min, max}, or null when empty or not cartesian.
      Overrides:
      getYBounds in class Series
    • captureTransitionStart

      protected void captureTransitionStart()
      Description copied from class: Series
      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.
      Overrides:
      captureTransitionStart in class Series
    • captureEntryStart

      protected void captureEntryStart()
      Description copied from class: Series
      Records a zero baseline as the start of the entry animation.
      Overrides:
      captureEntryStart in class Series
    • paint

      public void paint(ChartContext ctx)
      Description copied from class: Series

      Paints the series.

      Parameters
      • ctx: the current frame: graphics, plot area, axes and animation progress
      Specified by:
      paint in class Series
    • paintLegendSymbol

      public void paintLegendSymbol(Graphics g, int x, int y, int size)
      Description copied from class: Series

      Paints the legend swatch.

      Parameters
      • g: graphics

      • x: swatch left

      • y: swatch top

      • size: swatch size

      Overrides:
      paintLegendSymbol in class Series
    • 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.
      Overrides:
      getPointCount in class Series
    • getPoint

      public ChartPoint getPoint(ChartContext ctx, int index)
      Description copied from class: Series
      The point at index for a shared tooltip, or null.
      Overrides:
      getPoint in class Series
    • hitTest

      public ChartPoint hitTest(ChartContext ctx, int x, int y, int radius)
      Description copied from class: Series

      Finds the data point nearest a screen position.

      Parameters
      • ctx: the frame the series was last painted in

      • x: chart relative x

      • y: chart relative y

      • radius: how far from the point a touch may land and still hit it

      Returns

      the point, or null

      Overrides:
      hitTest in class Series
    • formatValue

      public String formatValue(ChartContext ctx, double value)
      Description copied from class: Series
      Formats a value for a label or tooltip.
      Overrides:
      formatValue in class Series
    • formatTooltip

      public String formatTooltip(ChartContext ctx, ChartPoint p)
      Description copied from class: Series

      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: the last paint context

      • p: the point

      Returns

      one line of text

      Overrides:
      formatTooltip in class Series
    • collectTableRows

      public void collectTableRows(List<String[]> rows)
      Description copied from class: Series

      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: the list to append rows to
      Overrides:
      collectTableRows in class Series