All Packages Class Hierarchy This Package Previous Next Index
Class com.objectplanet.chart.PieChart
java.lang.Object
|
+----java.awt.Component
|
+----com.objectplanet.chart.Chart
|
+----com.objectplanet.chart.PieChart
- public class PieChart
- extends Chart
This class implements a piechart component. The pie chart can be
displayed either in 2D or 3D mode. In 3D mode the depth and degree
of the pie can be adjusted. The pie segments as well as the legend
labels can be selected by the user.
The following attributes can be set:
- the chart title
- the chart title font
- the legend position
- the legend label colors
- the legend label fonts
- the chart background color
- the chart foreground color
- the pie angle (in 3D mode)
- the pie depth (in 3D mode)
- the number of decimals used for the sample values
- the number of decimals used for the percentage values
- the color of each pie segment
You can turn on or off the following feature:
- 2D or 3D display
- the chart title
- the legend
- the sample value labels
- the sample percentage labels
The following code creates a pie chart with four samples (segments).
// create the chart and its samples
PieChart chart = new PieChart(4);
long[] values = new long[] {100, 150, 70, 200};
String[] labels = new String[] {"one", "two", "three", "four"};
// set the chart attributes
chart.setTitle("Pie Chart");
chart.setSampleValues(values);
chart.setSampleLabels(labels);
// set the chart features
chart.set3DModeOn(true);
chart.setTitleOn(true);
chart.setLegendOn(true);
chart.setValueLabelsOn(true);
chart.setPercentLabelsOn(true);
- segment values are set to 100, 150, 70, and 200
- segment labels are set to "one", "two", "three", and "four"
- chart title is set to "Pie Chart"
- 3D mode is turned on
- title is turned on
- legend is turned on
- value labels turned on
- percent labels turned on
- Author:
- Bjorn J. Kvande.
-
PieChart()
- Creates a pie chart with 5 samples.
-
PieChart(int)
- Creates a pie chart with the given number of pie segments.
-
checkSelection(Point)
- Checks if a pie segment or legend label was selected.
-
getAngle()
- Gets the angle of the pie chart.
-
getDepth()
- Gets the depth of the pie.
-
getGraphBounds()
-
Calculates the bounding rectangle of the graph itself,
based on which features are on and how they are configured.
-
getPercentDecimalCount()
- Gets the number of decimals used with the percent values.
-
getPercentValue(int)
- Gets the value of the given pie segment as a percentage value
(out of 100).
-
isPercentLabelsOn()
- Checks if the percent labels are turned on.
-
isSampleLabelsOn()
- Checks if the sample label is turned on.
-
render(Graphics)
- Renders the bar chart according to the current chart attributes
and GUI state values.
-
setAngle(int)
-
Sets the angle of the pie chart.
-
setDepth(float)
- Sets the depth of the pie.
-
setPercentDecimalCount(int)
- Sets the number of decimals to use with the percent values.
-
setPercentLabelsOn(boolean)
- Display percent labels when the mouse pointer is above the pie segment.
-
setSampleLabelsOn(boolean)
- Display the sample label when the mouse pointer is above the pie segment.
PieChart
public PieChart()
- Creates a pie chart with 5 samples.
PieChart
public PieChart(int count)
- Creates a pie chart with the given number of pie segments.
- Parameters:
- count - The number of pie segments for the chart.
getPercentValue
public double getPercentValue(int index)
- Gets the value of the given pie segment as a percentage value
(out of 100).
- Parameters:
- index - The index of the pie segment (0-based).
- Returns:
- The number of percent the specified segment occupies.
setAngle
public void setAngle(int angle)
- Sets the angle of the pie chart. The default angle is 20.
- Parameters:
- angle - (0-80).
- See Also:
- setDepth
getAngle
public int getAngle()
- Gets the angle of the pie chart.
- Returns:
- The angle in degrees (0-90).
setDepth
public void setDepth(float depth)
- Sets the depth of the pie. The depth is a fraction of the width
of the pie. If the depth is set to 1.0, the depth is the same
as the width. The default depth is set to 0.4.
- Parameters:
- depth - The depth (0.0-1.0).
- See Also:
- setAngle
getDepth
public float getDepth()
- Gets the depth of the pie.
- Returns:
- a float in the range 0.0-1.0.
setPercentDecimalCount
public void setPercentDecimalCount(int count)
- Sets the number of decimals to use with the percent values.
The default is 0 decimals.
- Parameters:
- count - The number of decimals to use.
getPercentDecimalCount
public int getPercentDecimalCount()
- Gets the number of decimals used with the percent values.
setPercentLabelsOn
public void setPercentLabelsOn(boolean on)
- Display percent labels when the mouse pointer is above the pie segment.
The label shows the percent the pie segment occupies of the whole pie.
If the value labels are turned on both of them will be displayed.
- Parameters:
- on - True for on, false for off.
- See Also:
- setValueLabelsOn
isPercentLabelsOn
public boolean isPercentLabelsOn()
- Checks if the percent labels are turned on.
- Returns:
- True if on, false if off.
setSampleLabelsOn
public void setSampleLabelsOn(boolean on)
- Display the sample label when the mouse pointer is above the pie segment.
- Parameters:
- on - True for on, false for off (default).
isSampleLabelsOn
public boolean isSampleLabelsOn()
- Checks if the sample label is turned on.
- Returns:
- True if on, false if off.
checkSelection
protected ChartSample checkSelection(Point point)
- Checks if a pie segment or legend label was selected.
- Parameters:
- point - The point clicked on.
- Returns:
- The pie segment selected, or null if no segment was selected.
- Overrides:
- checkSelection in class Chart
getGraphBounds
public Rectangle getGraphBounds()
- Calculates the bounding rectangle of the graph itself,
based on which features are on and how they are configured.
render
public void render(Graphics g)
- Renders the bar chart according to the current chart attributes
and GUI state values.
- Overrides:
- render in class Chart
All Packages Class Hierarchy This Package Previous Next Index