How to display date in HH:mm:ss format in JasperReports?
I am using following code to generate chart in JasperReports.
<xyLineChart>
<chart evaluationTime="Band">
<reportElement x="0" y="0" width="555" height="500"/>
</chart>
<xyDataset>
<dataset incrementType="None"/>
<xySeries>
开发者_开发问答 <seriesExpression><![CDATA["CpuUsageGraph"]]></seriesExpression>
<xValueExpression><![CDATA[new Long($F{time}.getTime())]]></xValueExpression>
<yValueExpression><![CDATA[$F{cpuUsage}]]></yValueExpression>
</xySeries>
</xyDataset>
<linePlot>
<plot/>
</linePlot>
</xyLineChart>
I am printing the date on the X-axis, but it is displaying in milliseconds.
How do I display it in hh:mm:ss
format?
You can use following code in Java:
new SimpleDateFormat("MM-dd-yyyy HH:mm:ss z").format($V{VAR_DATE})
where $V{VAR_DATE} is the date variable to be converted into the format.
Or you could just put the date variable in a text field and then, go the the properties view, and write this in the Pattern field: HH:mm:ss. It could be useful to also check the "Blank when null" checkbox
Simply, You can add in pattern
property of the text field of date.
the field should be in java.sql.Date
format
You can write in pattern
HH:mm:ss
The property you are looking for is the "time axis tick label mask". There is no "pattern" field for a time series chart.
<xyLineChart>
<chart evaluationTime="Band">
<reportElement x="0" y="0" width="555" height="500"/>
</chart>
<xyDataset>
<dataset incrementType="None"/>
<xySeries>
<seriesExpression><![CDATA["CpuUsageGraph"]]></seriesExpression>
<xValueExpression><![CDATA[new Long($F{time}.getTime())]]></xValueExpression>
<yValueExpression><![CDATA[$F{cpuUsage}]]></yValueExpression>
</xySeries>
</xyDataset>
<linePlot>
<plot/>
</linePlot>
</xyLineChart>
public static final String DATE_TIME_FORMAT ="yyyy-dd-MM'T'HH:mm:ss.SSS";
DateFormat df = new SimpleDateFormat(DATE_TIME_FORMAT); df.format($V{VAR_DATE})
Specify the "Time Period" as "minute" under the 'details' section of the chart details.
timePeriod="Minute"
From JasperReports Ultimate Guide: Time Period Expression
This expression returns a java.util.Date value from which the engine will extract the corresponding time period depending on the value set for the timePeriod attribute mentioned earlier in the Time Series dataset. For instance, if the chart is about yearly data, the engine will extract only the year from the date value, or if you are gathering monthly data, the engine will use only the month value from the date object returned by this expression.
精彩评论