18.2. Charting

Charting support is also provided with jboss-seam-pdf.jar. Charts can be used in PDF documents, or as images in an HTML page. To use charting, you will need to add the JFreeChart library (jfreechart.jar and jcommon.jar) to the WEB-INF/lib directory. Three types of charts are currently supported: pie charts, bar charts and line charts.
<p:chart>
Description
Displays a chart already created in Java by a Seam component.
Attributes
  • chart -- The chart object to display
  • height -- The height fo the chart
  • width -- The width of the chart
Usage
<p:chart chart="#{mycomponent.chart}" width="500" height="500" />
<p:barchart>
Description
Displays a bar chart.
Attributes
  • borderVisible — Controls whether or not a border is displayed around the entire chart.
  • borderPaint — The color of the border, if visible.
  • borderBackgroundPaint — The default background color of the chart.
  • borderStroke
  • domainAxisLabel — The text label for the domain axis.
  • domainLabelPosition — The angle of the domain axis category labels. Valid values are STANDARD, UP_45, UP_90, DOWN_45 and DOWN_90. The value can also be a positive or negative angle in radians.
  • domainAxisPaint — The color of the domain axis label.
  • domainGridlinesVisible— Controls whether or not gridlines for the domain axis are shown on the chart.
  • domainGridlinePaint— The color of the domain gridlines, if visible.
  • domainGridlineStroke — The stroke style of the domain gridlines, if visible.
  • height — The height of the chart.
  • width — The width of the chart.
  • is3D — A Boolean value indicating that the chart should be rendered in 3D instead of 2D.
  • legend — A Boolean value indicating whether or not the chart should include a legend.
  • legendItemPaint— The default color of the text labels in the legend.
  • legendItemBackgoundPaint— The background color for the legend, if different from the chart background color.
  • legendOutlinePaint— The color of the border around the legend.
  • orientation — The orientation of the plot, either vertical (the default) or horizontal.
  • plotBackgroundPaint — The color of the plot background.
  • plotBackgroundAlpha — The alpha (transparency) level of the plot background. This should be a number between 0 (completely transparent) and 1 (completely opaque).
  • plotForegroundAlpha — The alpha (transparency) level of the plot. This should be a number between 0 (completely transparent) and 1 (completely opaque).
  • plotOutlinePaint — The color of the range gridlines, if visible.
  • plotOutlineStroke — The stroke style of the range gridlines, if visible.
  • rangeAxisLabel — The text label for the range axis.
  • rangeAxisPaint — The color of the range axis label.
  • rangeGridlinesVisible — Controls whether or not gridlines for the range axis are shown on the chart.
  • rangeGridlinePaint — The color of the range gridlines, if visible.
  • rangeGridlineStroke — The stroke style of the range gridlines, if visible.
  • title — The chart title text.
  • titlePaint — The color of the chart title text.
  • titleBackgroundPaint — The background color around the chart title.
  • width — The width of the chart.
Usage
<p:barchart title="Bar Chart" legend="true" width="500" height="500">
  <p:series key="Last Year">
    <p:data columnKey="Joe" value="100" />
    <p:data columnKey="Bob" value="120" />
  </p:series>        
  <p:series key="This Year">
    <p:data columnKey="Joe" value="125" />
    <p:data columnKey="Bob" value="115" />
  </p:series>
</p:barchart>
<p:linechart>
Description
Displays a line chart.
Attributes
  • borderVisible — Controls whether or not a border is displayed around the entire chart.
  • borderPaint — The color of the border, if visible.
  • borderBackgroundPaint — The default background color of the chart.
  • borderStroke
  • domainAxisLabel — The text label for the domain axis.
  • domainLabelPosition — The angle of the domain axis category labels. Valid values are STANDARD, UP_45, UP_90, DOWN_45 and DOWN_90. The value can also be a positive or negative angle in radians.
  • domainAxisPaint — The color of the domain axis label.
  • domainGridlinesVisible— Controls whether or not gridlines for the domain axis are shown on the chart.
  • domainGridlinePaint— The color of the domain gridlines, if visible.
  • domainGridlineStroke — The stroke style of the domain gridlines, if visible.
  • height — The height of the chart.
  • width — The width of the chart.
  • is3D — A Boolean value indicating that the chart should be rendered in 3D instead of 2D.
  • legend — A Boolean value indicating whether or not the chart should include a legend.
  • legendItemPaint — The default color of the text labels in the legend.
  • legendItemBackgoundPaint — The background color for the legend, if different from the chart background color.
  • legendOutlinePaint — The color of the border around the legend.
  • orientation — The orientation of the plot, either vertical (the default) or horizontal.
  • plotBackgroundPaint — The color of the plot background.
  • plotBackgroundAlpha — The alpha (transparency) level of the plot background. It should be a number between 0 (completely transparent) and 1 (completely opaque).
  • plotForegroundAlpha — The alpha (transparency) level of the plot. It should be a number between 0 (completely transparent) and 1 (completely opaque).
  • plotOutlinePaint — The color of the range gridlines, if visible.
  • plotOutlineStroke — The stroke style of the range gridlines, if visible.
  • rangeAxisLabel — The text label for the range axis.
  • rangeAxisPaint — The color of the range axis label.
  • rangeGridlinesVisible — Controls whether or not gridlines for the range axis are shown on the chart.
  • rangeGridlinePaint — The color of the range gridlines, if visible.
  • rangeGridlineStroke — The stroke style of the range gridlines, if visible.
  • title — The chart title text.
  • titlePaint — The color of the chart title text.
  • titleBackgroundPaint — The background color around the chart title.
  • width — The width of the chart.
Usage
<p:linechart title="Line Chart" width="500" height="500">
  <p:series key="Prices">
    <p:data columnKey="2003" value="7.36" />
    <p:data columnKey="2004" value="11.50" />
    <p:data columnKey="2005" value="34.625" />
    <p:data columnKey="2006" value="76.30" />
    <p:data columnKey="2007" value="85.05" />
  </p:series>
</p:linechart>
<p:piechart>
Description
Displays a pie chart.
Attributes
  • title — The chart title text.
  • label — The default label text for pie sections.
  • legend — A Boolean value indicating whether or not the chart should include a legend. Default value is true.
  • is3D — A Boolean value indicating that the chart should be rendered in 3D instead of 2D.
  • labelLinkMargin — The link margin for labels.
  • labelLinkPaint — The paint used for the label linking lines.
  • labelLinkStroke — The stroke used for the label linking lines.
  • labelLinksVisible — A flag that controls whether or not the label links are drawn.
  • labelOutlinePaint — The paint used to draw the outline of the section labels.
  • labelOutlineStroke — The stroke used to draw the outline of the section labels.
  • labelShadowPaint — The paint used to draw the shadow for the section labels.
  • labelPaint — The color used to draw the section labels.
  • labelGap — The gap between the labels and the plot, as a percentage of the plot width.
  • labelBackgroundPaint — The color used to draw the background of the section labels. If this is null, the background is not filled.
  • startAngle — The starting angle of the first section.
  • circular — A Boolean value indicating that the chart should be drawn as a circle. If false, the chart is drawn as an ellipse. The default is true.
  • direction — The direction in which the pie sections are drawn. One of: clockwise or anticlockwise. The default is clockwise.
  • sectionOutlinePaint — The outline paint for all sections.
  • sectionOutlineStroke — The outline stroke for all sections.
  • sectionOutlinesVisible — Indicates whether an outline is drawn for each section in the plot.
  • baseSectionOutlinePaint — The base section outline paint.
  • baseSectionPaint — The base section paint.
  • baseSectionOutlineStroke — The base section outline stroke.
Usage
<p:piechart title="Pie Chart" circular="false" 
            direction="anticlockwise" startAngle="30" 
            labelGap="0.1" labelLinkPaint="red">    
  <p:series key="Prices"> 
    <p:data key="2003" columnKey="2003" value="7.36" /> 
    <p:data key="2004" columnKey="2004" value="11.50" /> 
    <p:data key="2005" columnKey="2005" value="34.625" /> 
    <p:data key="2006" columnKey="2006" value="76.30" /> 
    <p:data key="2007" columnKey="2007" value="85.05" /> 
  </p:series> 
</p:piechart>
<p:series>
Description
Category data can be broken down into series. The series tag is used to categorize a data set with a series and apply styling to the entire series.
Attributes
  • key — The series name.
  • seriesPaint — The color of each item in the series.
  • seriesOutlinePaint — The outline color for each item in the series.
  • seriesOutlineStroke — The stroke used to draw each item in the series.
  • seriesVisible — A Boolean indicating if the series should be displayed.
  • seriesVisibleInLegend — A Boolean indicating whether the series should be listed in the legend.
Usage
<p:series key="data1"> 
  <ui:repeat value="#{data.pieData1}" var="item"> 
    <p:data columnKey="#{item.name}" 
            value="#{item.value}" /> 
  </ui:repeat> 
</p:series>
<p:data>
Description
The data tag describes each data point to be displayed in the graph.
Attributes
  • key — The name of the data item.
  • series — The series name, when not embedded inside a <p:series>.
  • value — The numeric data value.
  • explodedPercent — For pie charts, indicates how exploded from the pie a piece is.
  • sectionOutlinePaint — For bar charts, the color of the section outline.
  • sectionOutlineStroke — For bar charts, the stroke type for the section outline.
  • sectionPaint — For bar charts, the color of the section.
Usage
<p:data key="foo" value="20" sectionPaint="#111111" explodedPercent=".2" /> 
<p:data key="bar" value="30" sectionPaint="#333333" /> 
<p:data key="baz" value="40" sectionPaint="#555555" 
   sectionOutlineStroke="my-dot-style" />
<p:color>
Description
The color component declares a color or gradient for filled shapes.
Attributes
  • color — The color value. For gradient colors, this indicates the starting color. See Section 18.1.7.1, “Color Values” for color values.
  • color2 — For gradient colors, this is the color that ends the gradient.
  • point — The coordinates that mark the beginning of the gradient color.
  • point2 — The coordinates that mark the end of the gradient color.
Usage
<p:color id="foo" color="#0ff00f"/> 
<p:color id="bar" color="#ff00ff" color2="#00ff00" 
   point="50 50" point2="300 300"/>
<p:stroke>
Description
Describes a stroke used to draw lines in a chart.
Attributes
  • width — The width of the stroke.
  • cap — The line cap type. Valid values are butt, round and square
  • join — The line join type. Valid values are miter, round and bevel
  • miterLimit — For miter joins, this value is the limit of the size of the join.
  • dash — The dash value sets the dash pattern used to draw the line. Use space-separated integers to indicate the length of each alternating drawn and undrawn segment.
  • dashPhase — The dash phase indicates the point in the dash pattern that corresponds to the beginning of the stroke.
Usage
<p:stroke id="dot2" width="2" cap="round" join="bevel" dash="2 3" />