JasperReports Ultimate Guide - Sample Reference - Schema Reference - Configuration Reference - API (Javadoc)
|
|
|
|
JasperReports - JFreeChart Spider Chart Component Sample (version 4.6.0) | ![]() |
|
|
|
Main Features in This Sample | |
| Using the Built-in Spider Chart Component |
![]() | ![]() | ![]() | ![]() |
|
|
|
top | ||||||
|
||||||
![]() | Using the Built-in Spider Chart Component | Documented by Sanda Zaharia | ||||
|
||||||
| Description / Goal |
| How to configure the built-in spider chart component rendered by the JFreeChart library. | |||
| Since |
| 3.7.4 | |||
| Other Samples |
|
|
|||
|
||||||
|
The Built-in Spider Chart Component - Overview
Spider charts (also known as radar charts) are very useful when multivariate data sets have to be represented. Such data sets are usually displayed as overlapping spider webs anchored in a multiple radial axis system. The JR built-in spider chart was developed as component element in order to illustrate how to implement custom components based on the JFreeChart charting engine. The component in this case should output a JFreeChart object, collecting its data from an usual CategoryDataset, but rendering it as a spider web based on the SpiderWebPlot API. According to the component's schema, the content of a spider chart component is structured in 3 complementary elements, each one prefixed with the c: namespace prefix:
evaluationTime and evaluationGroup attributes:
<element name="spiderChart" substitutionGroup="jr:component"> <complexType> <complexContent> <extension base="jr:componentType"> <sequence> <element ref="c:chartSettings" /> <element ref="c:spiderDataset" /> <element ref="c:spiderPlot" /> </sequence> <attribute name="evaluationTime" type="jr:basicEvaluationTime" use="optional" default="Now"/> <attribute name="evaluationGroup" type="string" use="optional"/> </extension> </complexContent> </complexType> </element>Chart Settings In The Spider Chart Component In the <chartSettings> element one can configure the following structure similar to the
<chart> element in usual JR charts:
jr: prefix may be omitted.
The attributes below are also available for the <chartSettings> element, with the same meaning as in usual JR charts:
<element name="chartSettings"> <complexType> <sequence> <element ref="jr:chartTitle" minOccurs="0" maxOccurs="1"/> <element ref="jr:chartSubtitle" minOccurs="0" maxOccurs="1"/> <element ref="jr:chartLegend" minOccurs="0" maxOccurs="1"/> <element ref="jr:anchorNameExpression" minOccurs="0" maxOccurs="1"/> <element ref="jr:hyperlinkReferenceExpression" minOccurs="0" maxOccurs="1"/> <element ref="jr:hyperlinkAnchorExpression" minOccurs="0" maxOccurs="1"/> <element ref="jr:hyperlinkPageExpression" minOccurs="0" maxOccurs="1"/> <element ref="jr:hyperlinkTooltipExpression" minOccurs="0" maxOccurs="1"/> <element ref="jr:hyperlinkParameter" minOccurs="0" maxOccurs="unbounded"/> </sequence> <attribute name="isShowLegend" use="optional"> <simpleType> <restriction base="string"> <enumeration value="true"/> <enumeration value="false"/> </restriction> </simpleType> </attribute> <attribute name="backcolor" type="string" use="optional"> <annotation> <documentation>Background color of the chart</documentation> </annotation> </attribute> <attribute name="hyperlinkType" type="string" use="optional"/> <attribute name="hyperlinkTarget" type="string" use="optional"/> <attribute name="bookmarkLevel" type="NMTOKEN" use="optional" default="0"/> <attribute name="customizerClass" type="string" use="optional"/> <attribute name="renderType" type="string" use="optional"/> </complexType> </element>The Spider Dataset The spider dataset is a JRElementDataset based on category series. It contains the same structure as the <categoryDataset> element in usual JR charts:
jr: prefix may be omitted in a regular JRXML file.
The Spider Web Plot The spider plot element displays available data in the form of a "spider web", depending on specific settings. Multiple series can be plotted on the same (category) axis. Neither tick marks and tick labels nor negative values on axis are supported for the moment. The following attributes can be used to configure a spider plot:
labelFont element for the spider plot, and a maxValueExpression representing the maximum value any category axis can take.
The Spider Chart Sample Here is the piece of code used to configure the spider chart in the JRXML sample: <componentElement> <reportElement x="50" y="90" width="400" height="400" mode="Opaque"/> <c:spiderChart xmlns:c="http://jasperreports.sourceforge.net/jasperreports/components" evaluationTime="Now"> <c:chartSettings isShowLegend="true" backcolor="green" customizerClass="SpiderChartCustomizer"> <chartTitle position="Top"> <font isItalic="true" size="12"/> <titleExpression><![CDATA["Spider Chart"]] ></titleExpression> </chartTitle> <chartSubtitle color="blue"> <font isBold="true" size="6"/> <subtitleExpression><![CDATA["Chart Displaying Spider Web Contours"]] ></subtitleExpression> </chartSubtitle> <chartLegend backgroundColor="#eeffee"> <font size="6"/> </chartLegend> <hyperlinkTooltipExpression><![CDATA["Spider Chart"]] ></hyperlinkTooltipExpression> </c:chartSettings> <c:spiderDataset> <dataset incrementType="Group" incrementGroup="category"/> <categorySeries> <seriesExpression><![CDATA[$F{series}]] ></seriesExpression> <categoryExpression><![CDATA[$F{category}]] ></categoryExpression> <valueExpression><![CDATA[$F{value}]] ></valueExpression> <itemHyperlink hyperlinkType="Reference" hyperlinkTarget="Blank"> <hyperlinkReferenceExpression> <![CDATA["http://www.jfree.org/jfreechart/api/javadoc/org/jfree/chart/plot/SpiderWebPlot.html"]] > </hyperlinkReferenceExpression> </itemHyperlink> </categorySeries> </c:spiderDataset> <c:spiderPlot rotation="Anticlockwise" startAngle="39" interiorGap="0.2" labelGap="0.05" headPercent="0.01" axisLineColor="#ff0000" backcolor="yellow" axisLineWidth="2.0" tableOrder="Row"> <labelFont> <font isBold="true" isItalic="true" size="6"/> </labelFont> <c:maxValueExpression><![CDATA[Double.valueOf(10)]] ></c:maxValueExpression> </c:spiderPlot> </c:spiderChart> </componentElement>The resulting spider chart will have a green background, an italicized title and a blue subtitle, a legend with its own background color and font size, and a plot with rotation anticlockwise, start angle = 39deg, red axis, yellow backcolor and italicized bold labels on axis. See also how the interior gaps and axis line widths were set. Note also that the plot outline in the spider chart is customized via the SpiderChartCustomizer class. Running the Sample Running the sample requires the Apache Ant library. Make sure that ant is already installed on your system (version 1.5 or later).
In a command prompt/terminal window set the current folder to demo/samples/spiderchartcomponent within the JasperReports source project and run the > ant test view command.
It will generate all supported document types containing the sample report in the demo/samples/spiderchartcomponent/build/reports directory.
Then the report will open in the JasperReports internal viewer. |
|||||
|
|
© 2001- Jaspersoft Corporation www.jaspersoft.com |