Class BarChart


public final class BarChart extends CartesianChart<BarChart>
Bars, grouped or stacked, vertical or horizontal.

Series stand side by side in each category by default. CartesianChart.setStacked(boolean) accumulates them instead; series that name the same stack key share a column, and different keys stand side by side, so a chart can show two stacks per category. Negative values stack downward on their own side of zero.

The value axis begins at zero: the length of a bar is the value it stands for, and an axis that starts anywhere else draws a ratio the data does not have. It can be overridden; it should not be.


 BarChart chart = new BarChart();
 chart.setLabels("Q1", "Q2", "Q3", "Q4");
 chart.addSeries(ChartSeries.of("Direct",  120, 145, 132, 168));
 chart.addSeries(ChartSeries.of("Partner",  80,  92, 105,  99));
 chart.setStacked(true);
 
  • Constructor Details

    • BarChart

      public BarChart()
      An empty bar chart: add labels and series before it has anything to draw.
  • Method Details

    • of

      public static BarChart of(List<String> labels, ChartSeries... series)
      A bar chart over labels, with the given series.
    • barRadius

      public float barRadius()
      Corner radius of a bar's outer end, in logical points.
    • setBarRadius

      public BarChart setBarRadius(float value)
      Rounds the outer end of every bar; the end standing on the baseline stays square, so the bar still reads as anchored to zero rather than floating.
    • barPadding

      public float barPadding()
      The fraction of each category slot left empty, split between its two sides.
    • setBarPadding

      public BarChart setBarPadding(float fraction)
      Sets how much of each category slot is empty space, as a fraction in [0, 0.9] (default 0.22). 0 makes a histogram, where bars touch.
    • seriesGap

      public float seriesGap()
      Points of surface between two bars of the same category.
    • setSeriesGap

      public BarChart setSeriesGap(float points)
      Sets the gap between grouped bars, in logical points.
    • staggerFraction

      protected float staggerFraction()
      Bars wipe in from the first category rather than all appearing at once.
      Overrides:
      staggerFraction in class Chart<BarChart>
    • paintMarks

      protected void paintMarks(Canvas canvas)
      Description copied from class: CartesianChart
      Paints the marks inside the plot region; grid and axes are already down.
      Specified by:
      paintMarks in class CartesianChart<BarChart>
    • pickSeries

      protected int pickSeries(int category, float localX, float localY)
      Description copied from class: CartesianChart
      Which series a pointer inside category is reporting: the mark it is on if any, and otherwise the nearest one, so a click in the whitespace of a column still names a datum. -1 when the category has nothing visible in it.
      Specified by:
      pickSeries in class CartesianChart<BarChart>
    • pointOf

      protected ChartPoint pointOf(int seriesIndex, int category)
      Description copied from class: CartesianChart
      The datum for one series at one category, anchored at that series' mark.
      Specified by:
      pointOf in class CartesianChart<BarChart>
    • onAccessibility

      protected void onAccessibility(Accessibility a)
      One chart node, named by the title when there is one and carrying which way the bars' value axis runs, with one toggleable series node per series in paint order: the body every chart with axes shares, declared here because the coverage ratchet counts a hook the class declares itself.

      Every series is a node because every series is drawn: unlike a donut, a bar chart with one series and no legend still has that series on screen. A series' box is the legend entry a click toggles it on, the same rectangle the pointer is tested against, and never the union of its bars, which folds the entry animation in and would move on every frame of it; a series with no legend row keeps the chart's box, which is the honest answer to where it is. Its toggle state is the model's visibility bit and never the fade, so the frames of a fade damage the chart and publish nothing.

      Overrides:
      onAccessibility in class Widget<BarChart>
      Parameters:
      a - the node being described; write into it, and never keep it
    • onSyntheticAction

      protected boolean onSyntheticAction(long key, Accessible.Action action, Accessible.Argument arg)
      A toggle on a series node reaches the same path a click on its legend entry reaches, so a reader's toggle and a pointer's are one and the same to the chart and to the application, which is told nothing by either; refused when the legend is not interactive, when the series has no legend row for a pointer to have found, or when the key names no series.
      Overrides:
      onSyntheticAction in class Widget<BarChart>
      Parameters:
      key - the key this widget gave that child when it declared it
      action - what was asked
      arg - the argument, or Accessible.Argument.NONE
      Returns:
      whether this widget did it