Module platform

Class StackedBarRenderer

All Implemented Interfaces:
Serializable, Cloneable, LegendItemSource, CategoryItemRenderer, PublicCloneable
Direct Known Subclasses:
GroupedStackedBarRenderer

public class StackedBarRenderer extends BarRenderer implements Cloneable, PublicCloneable, Serializable
A stacked bar renderer for use with the CategoryPlot class. The example shown here is generated by the StackedBarChartDemo1.java program included in the JFreeChart Demo Collection:

StackedBarRendererSample.png
See Also:
  • Constructor Details

    • StackedBarRenderer

      public StackedBarRenderer()
      Creates a new renderer. By default, the renderer has no tool tip generator and no URL generator. These defaults have been chosen to minimise the processing required to generate a default chart. If you require tool tips or URLs, then you can easily add the required generators.
    • StackedBarRenderer

      public StackedBarRenderer(boolean renderAsPercentages)
      Creates a new renderer.
      Parameters:
      renderAsPercentages - a flag that controls whether the data values are rendered as percentages.
  • Method Details

    • getRenderAsPercentages

      public boolean getRenderAsPercentages()
      Returns true if the renderer displays each item value as a percentage (so that the stacked bars add to 100%), and false otherwise.
      Returns:
      A boolean.
      See Also:
    • setRenderAsPercentages

      public void setRenderAsPercentages(boolean asPercentages)
      Sets the flag that controls whether the renderer displays each item value as a percentage (so that the stacked bars add to 100%), and sends a RendererChangeEvent to all registered listeners.
      Parameters:
      asPercentages - the flag.
      See Also:
    • getPassCount

      public int getPassCount()
      Returns the number of passes (3) required by this renderer. The first pass is used to draw the bar shadows, the second pass is used to draw the bars, and the third pass is used to draw the item labels (if visible).
      Specified by:
      getPassCount in interface CategoryItemRenderer
      Overrides:
      getPassCount in class AbstractCategoryItemRenderer
      Returns:
      The number of passes required by the renderer.
    • findRangeBounds

      public Range findRangeBounds(CategoryDataset dataset)
      Returns the range of values the renderer requires to display all the items from the specified dataset.
      Specified by:
      findRangeBounds in interface CategoryItemRenderer
      Overrides:
      findRangeBounds in class AbstractCategoryItemRenderer
      Parameters:
      dataset - the dataset (null permitted).
      Returns:
      The range (or null if the dataset is empty).
    • calculateBarWidth

      protected void calculateBarWidth(CategoryPlot plot, Rectangle2D dataArea, int rendererIndex, CategoryItemRendererState state)
      Calculates the bar width and stores it in the renderer state.
      Overrides:
      calculateBarWidth in class BarRenderer
      Parameters:
      plot - the plot.
      dataArea - the data area.
      rendererIndex - the renderer index.
      state - the renderer state.
    • drawItem

      public void drawItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int row, int column, int pass)
      Draws a stacked bar for a specific item.
      Specified by:
      drawItem in interface CategoryItemRenderer
      Overrides:
      drawItem in class BarRenderer
      Parameters:
      g2 - the graphics device.
      state - the renderer state.
      dataArea - the plot area.
      plot - the plot.
      domainAxis - the domain (category) axis.
      rangeAxis - the range (value) axis.
      dataset - the data.
      row - the row index (zero-based).
      column - the column index (zero-based).
      pass - the pass index.
    • equals

      public boolean equals(Object obj)
      Tests this renderer for equality with an arbitrary object.
      Overrides:
      equals in class BarRenderer
      Parameters:
      obj - the object (null permitted).
      Returns:
      A boolean.