Class DonutChart
java.lang.Object
com.pdfjet.DonutChart
- All Implemented Interfaces:
Drawable
A donut or pie chart: each slice is its value's share of the sum of the
values, with a label next to it and its percentage inside it. A chart with
an inner radius of 0 is a pie chart. In the look of the other charts: a
title and a subtitle at the top left, thin white lines between the slices,
gray leader lines, the labels in ink, and each percentage white or ink by
its slice's color. See Example_28.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAdds a slice in the next color of the palette, blue first, the palette of BarChart, so that the charts of a document match; its ten colors repeat from the eleventh slice on.Adds a slice in the color.float[]Draws this chart on the specified page.setAltDescription(String altDescription) Sets the alternate description of the chart, which a screen reader reads in a PDF/UA document, where the chart is a figure.setCenterText(String centerText) Sets the text written in the hole of a donut chart, in the font of the title, as large as one and a half labels or as fits: the total, "100 crates".setLegend(boolean legend) Draws a legend under the circle, a swatch, the label and the percentage of each slice, in rows as wide as the circle, in place of the leader lines and the labels beside the circle: for many slices, or small ones whose labels would crowd.setLocation(float x, float y) Sets the top left corner of this chart: of its outer circle, or of its title when it has one, the circle under it.setRadii(float outerRadius, float innerRadius) Sets the outer and inner radius of this chart.setSubtitle(String subtitle) Sets the subtitle, drawn under the title in a muted gray.Sets the title, drawn at the top left of the chart's location in the bold font at the size of the labels; the circle is drawn under it.
-
Constructor Details
-
DonutChart
Creates a donut chart. With an inner radius of 0 it is a pie chart. Its fonts are in the order of the other charts': the bold one first.- Parameters:
bold- the bold font: the percentages inside the slices, the title and the text in the hole.regular- the regular font: the slice labels, the subtitle and the legend, and the size of the title.
-
-
Method Details
-
setLocation
Sets the top left corner of this chart: of its outer circle, or of its title when it has one, the circle under it. The center is one outer radius to the right of the corner of the circle and one below. The slice labels can extend past the circle.- Specified by:
setLocationin interfaceDrawable- Parameters:
x- the x coordinate of the top left corner.y- the y coordinate of the top left corner.- Returns:
- this DonutChart object.
-
setRadii
Sets the outer and inner radius of this chart.- Parameters:
outerRadius- the outer radius.innerRadius- the inner radius; 0 for a pie chart.- Returns:
- this DonutChart object.
-
add
Adds a slice in the next color of the palette, blue first, the palette of BarChart, so that the charts of a document match; its ten colors repeat from the eleventh slice on. The slice's share of the sum of the values sets its angle; a value that is not above 0 has no slice.- Parameters:
name- the label of the slice; empty for none.value- the value of the slice.- Returns:
- this DonutChart object.
-
add
Adds a slice in the color.- Parameters:
name- the label of the slice; empty for none.value- the value of the slice.color- the color as a 0xRRGGBB value, for example Color.blue.- Returns:
- this DonutChart object.
-
setTitle
Sets the title, drawn at the top left of the chart's location in the bold font at the size of the labels; the circle is drawn under it. A chart without the bold font, which draws no percentages, draws its title in the regular one. A chart without a title has the circle at its location.- Parameters:
title- the title.- Returns:
- this DonutChart object.
-
setSubtitle
Sets the subtitle, drawn under the title in a muted gray.- Parameters:
subtitle- the subtitle.- Returns:
- this DonutChart object.
-
setCenterText
Sets the text written in the hole of a donut chart, in the font of the title, as large as one and a half labels or as fits: the total, "100 crates". A text too wide for the hole at three quarters of a label is shortened with an ellipsis. A pie chart, with no hole, does not write it.- Parameters:
centerText- the text.- Returns:
- this DonutChart object.
-
setLegend
Draws a legend under the circle, a swatch, the label and the percentage of each slice, in rows as wide as the circle, in place of the leader lines and the labels beside the circle: for many slices, or small ones whose labels would crowd.- Parameters:
legend- true to draw the legend.- Returns:
- this DonutChart object.
-
setAltDescription
Sets the alternate description of the chart, which a screen reader reads in a PDF/UA document, where the chart is a figure. The default is the title, the subtitle and the text in the hole, as sentences, and the label and the percentage of each slice.- Parameters:
altDescription- the alternate description.- Returns:
- this DonutChart object.
-
drawOn
Draws this chart on the specified page.- Specified by:
drawOnin interfaceDrawable- Parameters:
page- the page to draw on, or null to measure the chart.- Returns:
- x and y coordinates of the bottom right corner of the chart: of its title, its circle, and its leader lines and labels, which can reach past the circle, or its legend. A chart with no slice above 0 draws nothing, not its title either, and returns the corner of its circle.
- Throws:
Exception- if an input or output exception occurred.
-