Class ChartFormats

java.lang.Object
limn.components.chart.ChartFormats

public final class ChartFormats extends Object
Ready-made number formats for axis ticks and tooltip values: what a chart puts on screen when the application does not supply its own Chart.setValueFormat(DoubleFunction).

Every format here follows the language in effect where it formats, read at that moment: a locale switch reaches charts already on screen, and a chart inside a subtree that declares its own locale formats in that subtree's language (ADR 035) — separators and digits alike — because the chart's passes hold its effective locale in scope. A format is a plain DoubleFunction<String>: anything else you write is equally acceptable, and reads the same scope for free by asking I18n.locale() when it formats.


 chart.setValueFormat(ChartFormats.compact());          // 12500 -> "12.5k"
 chart.valueAxis().setFormat(ChartFormats.unit(" ms")); // 16 -> "16 ms"
 
  • Method Details

    • number

      public static DoubleFunction<String> number()
      Grouped, with up to two decimals and no trailing zeros: 1234.5 reads "1,234.5" in English and "1.234,5" in German.
    • decimals

      public static DoubleFunction<String> decimals(int digits)
      Grouped with exactly digits decimals.
    • compact

      public static DoubleFunction<String> compact()
      Thousands folded into a suffix: 27600 reads "27.6k", 1_200_000 reads "1.2M". Values below 1000 are left alone.
    • percent

      public static DoubleFunction<String> percent(int digits)
      A fraction as a percentage: 0.42 reads "42%". Values that are already scaled to 0–100 want unit(String) with "%" instead.
    • unit

      public static DoubleFunction<String> unit(String suffix)
      number() with a fixed suffix: unit(" ms"), unit("%").
    • prefix

      public static DoubleFunction<String> prefix(String text)
      number() with a fixed prefix: prefix("$"), prefix("R$ ").