Class BarChart


public class BarChart extends CartesianChart
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()
  • 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
    • 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
    • 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
    • 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