Class ChartAxis

java.lang.Object
limn.components.chart.ChartAxis

public final class ChartAxis extends Object
One axis of a CartesianChart: the value axis that carries the numbers, or the category axis that carries the labels. Reach them with CartesianChart.valueAxis() and CartesianChart.categoryAxis(); both are created with the chart and live as long as it does.

An axis is automatic until told otherwise: it reads the data, rounds the range outward to values a human would have chosen, and picks a tick spacing near setTickCount(int). setMin(Double) and setMax(Double) pin either end; whichever end stays null keeps following the data.

Four settings apply only to the value axis and are ignored on the category axis, which has no numbers to place: min, max, tickCount and beginAtZero. format is likewise a value-axis setting; category labels come from Chart.setLabels(java.util.List).

  • Method Details

    • min

      public Double min()
      The pinned lower bound, or null while it follows the data.
    • setMin

      public ChartAxis setMin(Double value)
      Pins the lower bound; null hands it back to the data.
    • max

      public Double max()
      The pinned upper bound, or null while it follows the data.
    • setMax

      public ChartAxis setMax(Double value)
      Pins the upper bound; null hands it back to the data.
    • beginsAtZero

      public boolean beginsAtZero()
      Whether the automatic range always reaches zero.
    • setBeginAtZero

      public ChartAxis setBeginAtZero(boolean value)
      Whether the automatic range must include zero. On by default for bars, off for lines, and that difference is not a preference: the length of a bar is the value, so a bar axis that starts anywhere else draws a ratio that is not the data's. A line encodes value as position, so it may zoom into the range that matters.
    • tickCount

      public int tickCount()
      The tick count the automatic scale aims for.
    • setTickCount

      public ChartAxis setTickCount(int value)
      Sets how many ticks the automatic scale aims for (clamped to [2, 20]). It is a target, not a promise: the scale rounds the spacing to 1, 2 or 5 times a power of ten first, and honours that over the count.
    • format

      public DoubleFunction<String> format()
      How tick values are turned into text.
    • setFormat

      public ChartAxis setFormat(DoubleFunction<String> value)
      Sets the tick text format. Defaults to ChartFormats.number(); the chart's own Chart.setValueFormat(DoubleFunction) does not reach here, so an axis and its tooltips can read differently (compact ticks, exact tooltips).
    • hasGrid

      public boolean hasGrid()
      Whether this axis draws grid lines across the plot.
    • setGrid

      public ChartAxis setGrid(boolean value)
      Shows or hides this axis' grid lines (value axis on, category axis off by default).
    • isVisible

      public boolean isVisible()
      Whether this axis draws its labels at all.
    • setVisible

      public ChartAxis setVisible(boolean value)
      Shows or hides the axis labels. Hiding them gives the plot their gutter back, the shape a sparkline wants.
    • title

      public String title()
      The axis title, or null for none.
    • setTitle

      public ChartAxis setTitle(String value)
      Sets a title drawn beside the axis (null for none).