Can I set timestamp chart timeAxisFormat mask dynamically?

Hello,

 

I'm trying to make a line chart to show; x axis: date, y axis: value.

Since x axis is date, I created timestamp chart as so that the time axis labels can be skipping depend on its number automatically.

 

But when I try to set time axis label mask as a parameter, it gets error.

For example, I set 'tickLabelMask="$P{dateFormat}"' and 'java.lang.IllegalArgumentException: Illegal pattern character 'P' came out.

When I set 'tickLabelMask=<![CDATA[$P{dateFormat}]]>', 'Open quote is expected for attribute "tickLabelMask" associated with an  element type  "axisFormat".' came out.

 

In my application, my user selects his nation(even though he is not in that nation) and I have to show the time axis as a format of their nation.

So, I'm trying to pass a date format as an parameter..

 

Is there an way to mask date with parameter?

Or is there any way to make line chart x asix label skip?

 

I really need an advice.

 

Best,

 

S Kim

abbey8908's picture
Joined: Aug 6 2018 - 12:39am
Last seen: 4 years 8 months ago

.

abbey8908 - 4 years 8 months ago

2 Answers:

I dont know the datasource type you are using, but I'm assuming you are using a database.

All the databases should have some kind of date formatting patterns. here im using Oracle to_char and formatting the date based on a parameter.

<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.4.2.final using JasperReports Library version 6.4.1  -->
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="FormatMasking" pageWidth="842" pageHeight="595" orientation="Landscape" columnWidth="802" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="8acadd65-acc1-4694-8b00-b147ef2b539b">
    <property name="com.jaspersoft.studio.data.sql.tables" value=""/>
    <parameter name="dateFormat" class="java.lang.String">
        <defaultValueExpression><![CDATA["MM/DD/YYYY"]]></defaultValueExpression>
    </parameter>
    <queryString>
        <![CDATA[select value_field, timestampvaltochar
  from (select 1 as value_field,
               to_char(trunc(sysdate - 1), $P{dateFormat}) as timestampvaltochar,
               trunc(sysdate - 1) as timestampval
          from dual
        union all
        select 1 as value_field,
               to_char(trunc(sysdate - 2), $P{dateFormat}) as timestampvaltochar,
               trunc(sysdate - 2) as timestampval
          from dual
        union all
        select 2 as value_field,
               to_char(trunc(sysdate - 3), $P{dateFormat}) as timestampvaltochar,
               trunc(sysdate - 3) as timestampval
          from dual
        union all
        select 3 as value_field,
               to_char(trunc(sysdate - 2), $P{dateFormat}) as timestampvaltochar,
               trunc(sysdate - 2) as timestampval
          from dual
        union all
        select 6 as value_field,
               to_char(trunc(sysdate - 4), $P{dateFormat}) as timestampvaltochar,
               trunc(sysdate - 4) as timestampval
          from dual
        union all
        select 7 as value_field,
               to_char(trunc(sysdate - 6), $P{dateFormat}) as timestampvaltochar,
               trunc(sysdate - 6) as timestampval
          from dual
        union all
        select 8 as value_field,
               to_char(trunc(sysdate - 2), $P{dateFormat}) as timestampvaltochar,
               trunc(sysdate - 2) as timestampval
          from dual
        union all
        select 1 as value_field,
               to_char(trunc(sysdate - 8), $P{dateFormat}) as timestampvaltochar,
               trunc(sysdate - 8) as timestampval
          from dual)
 order by timestampval]]>
    </queryString>
    <field name="VALUE_FIELD" class="java.math.BigDecimal"/>
    <field name="TIMESTAMPVALTOCHAR" class="java.lang.String"/>
    <background>
        <band splitType="Stretch"/>
    </background>
    <summary>
        <band height="233" splitType="Stretch">
            <lineChart>
                <chart evaluationTime="Report">
                    <reportElement x="0" y="0" width="802" height="233" uuid="488b9167-8229-434a-a716-be421060c87b"/>
                    <chartTitle/>
                    <chartSubtitle/>
                    <chartLegend/>
                </chart>
                <categoryDataset>
                    <categorySeries>
                        <seriesExpression><![CDATA["TEMPVALUES"]]></seriesExpression>
                        <categoryExpression><![CDATA[$F{TIMESTAMPVALTOCHAR}]]></categoryExpression>
                        <valueExpression><![CDATA[$F{VALUE_FIELD}]]></valueExpression>
                    </categorySeries>
                </categoryDataset>
                <linePlot>
                    <plot/>
                    <categoryAxisFormat>
                        <axisFormat labelColor="#000000" tickLabelColor="#000000" tickLabelMask="" axisLineColor="#000000"/>
                    </categoryAxisFormat>
                    <valueAxisFormat>
                        <axisFormat labelColor="#000000" tickLabelColor="#000000" axisLineColor="#000000"/>
                    </valueAxisFormat>
                </linePlot>
            </lineChart>
        </band>
    </summary>
</jasperReport>

reportdev's picture
11254
Joined: Oct 12 2015 - 12:05pm
Last seen: 11 months 3 weeks ago

Dear Reportdev,

Thank you for your comment.

 

I will put max 365 date data, so I need the x aixs to be automatically skipped some points based on its amount.

So the only option for me is time series chart, not line chart.

And time series chart must has Timestamp or Date data type for time axis...

abbey8908's picture
Joined: Aug 6 2018 - 12:39am
Last seen: 4 years 8 months ago
Feedback
randomness