Reputation: 53
I am studying Java with Jasper Reports and I am trying to create a report with a XYLineChart
My report is ok all the data is showing the way I want. My chart is plotting all the data but the X and Y axis do not have a name (label
) so I can not "know" what that data is.
I wanna to put the names of my axis in the chart. I did some reading and find this in a book:
The Line plot also has two axes. Their labels can be controlled by using the categoryAxisLabelExpression and valueAxisLabelExpression...
The book gives the the syntax below:
<!ELEMENT linePlot (plot, categoryAxisLabelExpression?,
categoryAxisFormat?, valueAxisLabelExpression?, valueAxisFormat?)>
<!ATTLIST linePlot
isShowLines (true | false) "true"
isShowShapes (true | false) "true">
The jrxml
complete code is in my GitHub: Report
Below there are the lines,extracted from the code above, about the chart
:
</band>
<band height="164">
<xyLineChart>
<chart evaluationTime="Report">
<reportElement stretchType="ContainerHeight" x="20" y="20" width="280" height="144" uuid="e33fd328-3bfa-41f7-aa53-face45efaf74">
<propertyExpression name="net.sf.jasperreports.chart.range.axis.tick.interval"><![CDATA[value]]></propertyExpression>
</reportElement>
<box>
<topPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
</box>
<chartTitle/>
<chartSubtitle/>
<chartLegend/>
</chart>
<xyDataset>
<dataset resetType="Report">
<datasetRun subDataset="CorpoDeProvaChartDataSet" uuid="320307a6-07d6-4d08-8f42-0537af75c157">
<dataSourceExpression><![CDATA[$P{CorpoDeProvaChartCollectionBeanParam}]]></dataSourceExpression>
</datasetRun>
</dataset>
<xySeries autoSort="true">
<seriesExpression><![CDATA[$F{serie}]]></seriesExpression>
<xValueExpression><![CDATA[$F{days}]]></xValueExpression>
<yValueExpression><![CDATA[$F{fck}]]></yValueExpression>
<labelExpression><![CDATA["TEst"]]></labelExpression>
</xySeries>
</xyDataset>
<linePlot>
<plot/>
<categoryAxisFormat>
<axisFormat labelColor="#000000" tickLabelColor="#000000" axisLineColor="#000000"/>
</categoryAxisFormat>
<valueAxisFormat>
<axisFormat labelColor="#000000" tickLabelColor="#000000" axisLineColor="#000000"/>
</valueAxisFormat>
</linePlot>
</xyLineChart>
<textField>
<reportElement x="143" y="111" width="100" height="30" uuid="a6f5c887-cac8-4304-b8d5-8b9bb492ee39"/>
<textFieldExpression><![CDATA[$V{PAGE_NUMBER}]]></textFieldExpression>
</textField>
</band>
I tried to change my code like this, but It just gives me a error:
...
<categoryAxisFormat>
<axisFormat labelColor="#000000" tickLabelColor="#000000" axisLineColor="#000000"/>
<categoryAxisLabelExpression><![CDATA["Days"]]></categoryAxisLabelExpression>
</categoryAxisFormat>
<valueAxisFormat>
<axisFormat labelColor="#000000" tickLabelColor="#000000" axisLineColor="#000000"/>
<valueAxisLabelExpression><![CDATA["fck"]]</valueAxisLabelExpression>
</valueAxisFormat>
...
Also I could not find anything in the chart's properties tab of Jaspersoft Studio that would do the trick. And any reference I could find points to valueAxisLabelExpression
and valueAxisFormat
properties but I do not know how to set them.
Additional info:
subDataSets
with JRBeanCollectionDataSource
class
To summarize I wanna know how to put a label
in X and Y axis of a XYLineChart
in JasperReport.
Thank you all for the help.
Upvotes: 1
Views: 1484
Reputation: 53
After some tries and reading I did what I want.
At my first try I've used my chart
code like this:
<categoryAxisFormat>
<axisFormat labelColor="#000000" tickLabelColor="#000000" axisLineColor="#000000"/>
<categoryAxisLabelExpression><![CDATA["Days"]]></categoryAxisLabelExpression>
</categoryAxisFormat>
<valueAxisFormat>
<axisFormat labelColor="#000000" tickLabelColor="#000000" axisLineColor="#000000"/>
<valueAxisLabelExpression><![CDATA["fck"]]</valueAxisLabelExpression></valueAxisFormat>
But the correct sintax is:
<categoryAxisLabelExpression><![CDATA["Days"]]></categoryAxisLabelExpression>
<categoryAxisFormat>
<axisFormat labelColor="#000000" tickLabelColor="#000000" axisLineColor="#000000"/>
</categoryAxisFormat>
<valueAxisLabelExpression><![CDATA["fck (MPa)"]]></valueAxisLabelExpression>
<valueAxisFormat>
<axisFormat labelColor="#000000" tickLabelColor="#000000" axisLineColor="#000000"/>
</valueAxisFormat>
So I just had to change the lines order in my code. Thank you everyone...
Upvotes: 1