Class GeneralBarSeries

  • Direct Known Subclasses:
    BarSeries, BoxWhiskerSeries, MultiBarSeries, StackedBarSeries

    public abstract class GeneralBarSeries
    extends Series

    The superclass for all types of series that involve plotting Bars to an AxesGraph. Bars can be plotted against any type of axis, but generally a BarAxis will be used on the "x" axis (this is the default if none is specified).

    When plotting bars representing dates against a DateAxis, care must be taken to make sure the names of the bars match up against the values plotted on the axis, otherwise bars will go missing. For example, the first two values in this bar series will not appear on the graph:

      DateAxis axis = new DateAxis(new SimpleDateFormat("yyyy-MM-dd"));
      axesgraph.setAxis(Axis.BOTTOM, axis);
      BarSeries series = new BarSeries("dates");
      series.add("21 March 2004");               // Wrong
      series.add("2004-03-22 00:00");            // Wrong
      series.add("2004-03-23");                  // Right!
      axesgraph.addSeries(series);
     
    How much of a date each bar represents is determined by the format being used. In the example above each bar is assumed to represent one day (because the format used on the axis can only represent a day). Had we used the line
      DateAxis axis = new DateAxis(new SimpleDateFormat("yyyy-MM-dd HH:MM"));
     
    then each bar would represent one minute of time. If you want a bar to represent one hour, but still want to display the minutes on the axis, you could do something like this:
      DateAxis axis = new DateAxis(new SimpleDateFormat("yyyy-MM-dd HH:00"));
     

    See Also:
    DateAxis.setBarsAtNoon(boolean)
    • Method Detail

      • setStyle

        public void setStyle​(String name,
                             Style style)
        Set the style to use for a specific bar. Generally all bars in a series will have the same style, but this can be used to highlight an individual bar if necessary.
        Parameters:
        name - the name of the bar
        style - the style to paint the bar in
      • setBarWidth

        public void setBarWidth​(double width)
        Set the width of each bar. If you imagine a bar sitting on a square that's 1x1, by default the bar takes up the whole of that square. The setBarWidth(double) and setBarDepth(double) methods control how much of that square is filled. The default width and depth are both 1, ie. the whole square is used.
        Parameters:
        width - the width of the bar - must be 0 < width <= 1
      • setBarWidth

        public void setBarWidth​(double topwidth,
                                double bottomwidth)
        Set the width of each bar. Similar to setBarWidth(double), but this method allows you to "taper" the bar to be wider at the top or bottom. This method is used to draw pyramids instead of regular bar charts. All values must be between 0 and 1 inclusive.
        Parameters:
        topwidth - the width of the bar at the top
        bottomwidth - the width of the bar at the bottom
        Since:
        2.4
      • setBarWidth

        public void setBarWidth​(double topwidth,
                                double middlewidth,
                                double bottomwidth)
        Set the width of each bar. Similar to setBarWidth(double), but this method allows you to "taper" the bar to be wider at the top or bottom with a middle "waist". This method is used to draw "funnels" instead of regular bar charts. All values must be between 0 and 1 inclusive.
        Parameters:
        topwidth - the width of the bar at the top
        middlewidth - the width of the bar at the middle
        bottomwidth - the width of the bar at the bottom
        Since:
        2.4
      • setBarDepth

        public void setBarDepth​(double depth)
        Set the depth of each bar. If you imagine a bar sitting on a square that's 1x1, by default the bar takes up the whole of that square. The setBarWidth(double) and setBarDepth(double) methods control how much of that square is filled. The default width and depth are both 1, ie. the whole square is used.
        Parameters:
        depth - the depth of the bar - must be 0 < depth <= 1
      • setRoundBars

        public void setRoundBars​(boolean round)
        This method has been replaced with the more flexible setRoundBars(double). Passing true to this method is identical to calling setRoundBars(5).
        Parameters:
        round - whether to draw round bars or not
      • setRoundBars

        public void setRoundBars​(double size)
        By default bars are drawn as boxes, but by passing a non-zero value to this method you can draw your bars as cylinders for a slightly different effect - although as this generates more polygons it will result in longer processing time and (for vector output formats like SVG or PDF), a bigger file. The parameters is the number of degrees each polygon should occupy. Typically a value of between 2 and 5 is used to create round bars, but other interesting values are 45 or 60 (for octaganol or hexagonal bars). A value of zero results in regular rectangles.
        Parameters:
        size - the size of each edge in the polygon that is the bar - 0, or between 0.5 and 120
        Since:
        2.1.1
      • addMarker

        public void addMarker​(AbstractMarker marker,
                              String x,
                              double y)
        Add a Marker to this Series.
        Parameters:
        marker - the Marker to add
        x - the X co-ordinate to place the marker at as a String
        y - the Y co-ordinate to place the marker at