Class PieGraph


  • public class PieGraph
    extends Graph
    A subclass of graph for displaying data in a circular Pie graph. This is the only type of graph that isn't plotted against an Axis. Plotting a PieGraph is much simpler than plotting an AxesGraph. Here's a simple example:
     PieGraph graph = new PieGraph();
     graph.set("Apples", 200);
     graph.set("Oranges", 100);
     
    Labels can be added to each slice by calling the setLabel method.
    • Constructor Detail

      • PieGraph

        public PieGraph()
        Create a new PieGraph
    • Method Detail

      • addPolarMarker

        public void addPolarMarker​(AbstractMarker marker,
                                   double angle,
                                   double distance)
        Add an AbstractMarker at an arbitrary polar coordinate on the graph.
        Parameters:
        marker - the marker
        angle - the angle of the graph, in degrees clockwise from 12 o'clock
        distance - the distance from the center of the graph as a proportion of the radius; 1 is the radius of the graph.
        Since:
        2.4.6
      • addMarker

        public void addMarker​(AbstractMarker marker,
                              double x,
                              double y)
        Add an AbstractMarker at an arbitrary cartesion point on the graph. A value of (0,0) is the center of the graph, (0,100) is the 12 o'clock position and (100, 0) is the 3 o'clock position. The coordinate is subject to further adjustment by the X, Y and Z rotation values.
        Parameters:
        marker - the marker
        x - the X position of the marker, where -100 is the left side, 0 is the center and 100 the right-side of the graph.
        y - the Y position of the marker, where 100 is the top side, 0 is the center and -100 the bottom-side of the graph.
        Since:
        2.4.6
      • addLine

        public void addLine​(String name,
                            double x1,
                            double y1,
                            double x2,
                            double y2,
                            Style style)
        Add a line to the graph. These coordinates are subject to further adjustment by the X, Y and Z rotation values.
        Parameters:
        x1 - the first X position of the line, where -100 is the left side, 0 is the center and 100 the right-side of the graph.
        y1 - the first Y position of the line, where 100 is the top side, 0 is the center and -100 the bottom-side of the graph.
        x2 - the second X position of the line
        y2 - the second Y position of the line
        style - the Style to draw the line in
      • setDoughnut

        public void setDoughnut​(double size)
        Set the size of the "hole in the doughnut". By default this value is set to 0, which means there is no hole (the graph is a regular Pie graph). Values between 0 and 99 may be specified - 99 would result in a very thin ring graph.
        Parameters:
        size - the size of the doughnut hole - from 0 to 99
        Since:
        2.1
      • setSliceSize

        public void setSliceSize​(double size)
        Set the number of degrees each straight line makes up in a PieGraph. Smaller values give rounder pies and smoother shading, but will a) take longer to render and b) for vector files like PDF or SVG, result in larger files (although this may be minimized by compression in PDF). The default value in versions prior to 2.1 was 5, and since then is 2 (giving 2° steps). This value gives high quality results, but when painting with createPattern() will result in much slower rendering. The minimal value is 0.5 and the maximum is 5.
        Since:
        2.1.1
      • set

        public void set​(String name,
                        double value)
        Add a slice to the Pie. If a slice with this name already exists, it's value is replaced. To remove a slice completely, set the value to NaN. Note that since 2.3, 0 value slices are allowed.
        Parameters:
        name - the name of the slice
        value - the size of the slice
      • getProportion

        public double getProportion​(String name)
        Return the proportion of the pie that the named slice occupies. If the specified name is not in the pie this method returns 0. If you're using an "other" slice (by calling setOtherSlice(java.lang.String, double)), then passing in the name of that slice will give you the proportion it occupies.
        Parameters:
        name - the name of the slice to get the proportion of
        Returns:
        the proportion of the pie occupied by this slice, between 0 and 1
        Since:
        2.0.2
      • setColor

        public void setColor​(String name,
                             Paint color)
        Set the color for the specified slice
        Parameters:
        name - the name of the slice
        color - the color to paint the slice in
      • setStyle

        public void setStyle​(Style style)
        Set the overall style for the graph. This allows control over non-color features of the graph, such as border-color, thickness and so on.
        Since:
        2.0.4
      • setExtend

        public void setExtend​(String name,
                              double radius)
        Extend the specified slice away from the center of the pie. Since 2.4.6 this calls setExtend(name, radius, 0, 1)
        Parameters:
        name - the name of the slice
        radius - the distance from the center of the pie to move the slice, as a percentage of the radius of the pie. Typical values would be about 0.2
      • setExtend

        public void setExtend​(String name,
                              double centerradius,
                              double innerradius,
                              double outerradius)
        Extend the specified slice away from the center of the pie, and set the inner and outer radius of the slice.
        Parameters:
        name - the name of the slice
        centerradius - the distance from the center of the pie to move the slice, as a percentage of the radius of the pie. Typical values would be about 0.2
        innerradius - the distance from the center of the slice to the inner edge - a value of 0 draws a complete slice, a value of 0.5 will result in the inner 50% of the slice not being drawn - the slice is part of a "doughnut" rather than a pie.
        outerradius - the distance from the center of the slice to the outer edge - a value of 1 draws the slice the same size as the rest of the pie, a value of 1.2 will extend the slice 20% beyond the edge.
        Since:
        2.4.6
        See Also:
        setDoughnut(double)
      • setLabel

        public void setLabel​(String key,
                             AbstractMarker marker,
                             double distance)
        Set the label of one of the slices in the pie. This method replaces any existing labels on this slice and then calls addLabel() with null for the value of callout.
        Parameters:
        key - the slice to add the label to
        marker - the marker to display. May be a Text, Marker or Image
        distance - How far from the center of the pie to put the slice, as a ratio of the radius.For example, a value of 1.2 puts the marker just outside the edge of the pie and a value of 0.7 puts it inside the pie. A value of 0 or NaN will auto-position the label
        See Also:
        addLabel(java.lang.String, org.faceless.graph2.AbstractMarker, double, org.faceless.graph2.Style)
      • addLabel

        public void addLabel​(String key,
                             AbstractMarker marker,
                             double distance,
                             Style callout,
                             int align)
        Add a label to one of the slices in the pie. Whether the label is displayed on or off the Pie depends on whether distance is less than or greater than 0. Labels may be rotated by specifying a value to TextStyle.setRotate(double) when creating the label, and the special value TextStyle.ROTATE_AUTO may be used to cause labels to rotate to match the slice. Slices may have multiple labels.

        The optional callout parameter is the style to draw the line to that label in when distance is greater than 1. It may be null, in which case no line will be drawn.

        As a special case for Pie Graphs, if the marker is a Text object containing the text "0%%", "0.0%%" or "0.00%%", that text will be replaced by the the size of the slice as a percentage. If this isn't flexible enough the value from getProportion(java.lang.String) can be formatted as required.

        Parameters:
        key - the slice to add the label to
        marker - the marker to display. May be a Text, Marker or Image
        distance - How far from the center of the pie to put the slice, as a ratio of the radius.For example, a value of 1.2 puts the marker just outside the edge of the pie and a value of 0.7 puts it inside the pie.
        callout - The style to draw the line to the marker from the edge of the pie. For labels with a distance of < 0, this value is ignored.
        align - if non-zero, this alignment is set on the label instead of being automatically selected.
        Since:
        2.4.6
      • setDepth

        public void setDepth​(double depth)
        Set the depth of the Pie when it's displayed in 3-D. The default is 15, for 15%
        Parameters:
        depth - the depth of the Pie, as a percentage of the radius of the pie
      • setOtherSlice

        public void setOtherSlice​(String name,
                                  double percentage)
        Create an "Other" slice, which can be used to group slices that are too small to show useful information. By default, no "Other" slice is used.
        Parameters:
        name - the name to use for the slice
        percentage - the threshold to determine which slices to add. Any slices that would be smaller than this percentage are added to the other slice instead of being displayed directly. Zero means no other slice is used.