2

I have to set the min and max value on the y-axis in a lineChart of my jasperreport to a fixed value. This is due to comparability of the charts generated.

I've tried to use the customizerclass from jaspersoft's reportlibrary to do so. I got the jasperreports-chart-customizers-6.7.0.jar from https://community.jaspersoft.com/project/jasperreports-library/releases and placed it in my /WEB-INF/lib folder. i did import the class as well. but it does nothing.

<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.6.0.final using JasperReports Library version 6.6.0  -->
<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="jasper_report_template" pageWidth="842" pageHeight="595" orientation="Landscape" whenNoDataType="NoPages" columnWidth="822" leftMargin="10" rightMargin="10" topMargin="50" bottomMargin="40" uuid="c5395651-075a-4d6a-a971-d283cab77f63">
    <property name="com.jaspersoft.studio.unit." value="pixel"/>
    <property name="com.jaspersoft.studio.unit.pageHeight" value="pixel"/>
    <property name="com.jaspersoft.studio.unit.pageWidth" value="pixel"/>
    <property name="com.jaspersoft.studio.unit.topMargin" value="pixel"/>
    <property name="com.jaspersoft.studio.unit.bottomMargin" value="pixel"/>
    <property name="com.jaspersoft.studio.unit.leftMargin" value="pixel"/>
    <property name="com.jaspersoft.studio.unit.rightMargin" value="pixel"/>
    <property name="com.jaspersoft.studio.unit.columnWidth" value="pixel"/>
    <property name="com.jaspersoft.studio.unit.columnSpacing" value="pixel"/>
    <import value="net.sf.jasperreports.customizers.axis.RangeAxisCustomizer"/>
    <parameter name="ReportTitle" class="java.lang.String"/>
    <parameter name="Author" class="java.lang.String"/>
    <queryString>
        <![CDATA[]]>
    </queryString>
    <field name="day" class="java.lang.Integer">
        <fieldDescription><![CDATA[day]]></fieldDescription>
    </field>
    <field name="type" class="java.lang.String">
        <fieldDescription><![CDATA[type]]></fieldDescription>
    </field>
    <field name="dateAsString" class="java.lang.String">
        <fieldDescription><![CDATA[dateAsString]]></fieldDescription>
    </field>
    <field name="weekdayAsString" class="java.lang.String">
        <fieldDescription><![CDATA[weekdayAsString]]></fieldDescription>
    </field>
    <field name="time" class="java.lang.String">
        <fieldDescription><![CDATA[time]]></fieldDescription>
    </field>
    <field name="kwh" class="java.lang.Double">
        <fieldDescription><![CDATA[kwh]]></fieldDescription>
    </field>
    <sortField name="day"/>
    <sortField name="type"/>
    <group name="DayGroup" minHeightToStartNewPage="60">
        <groupExpression><![CDATA[$F{day}]]></groupExpression>
        <groupHeader>
            <band height="500" splitType="Stretch">
                <lineChart>
                    <chart evaluationTime="Group" evaluationGroup="DayGroup">
                        <reportElement x="0" y="0" width="800" height="500" uuid="2f4f1b7b-7b71-4440-80b0-3ab75e84196f">
                            <property name="net.sf.jasperreports.customizers.axis.rangeAxisCustomizer.minValue" value="1"/>
                            <property name="net.sf.jasperreports.customizers.axis.rangeAxisCustomizer.maxValue" value="30"/>
                            <property name="net.sf.jasperreports.customizers.axis.rangeAxisCustomizer.tickUnit" value="1"/>
                        </reportElement>
                        <chartTitle>
                            <titleExpression><![CDATA[$F{weekdayAsString}+", der "+$F{dateAsString}]]></titleExpression>
                        </chartTitle>
                        <chartSubtitle/>
                        <chartLegend>
                            <font size="10"/>
                        </chartLegend>
                    </chart>
                    <categoryDataset>
                        <dataset resetType="Group" resetGroup="DayGroup"/>
                        <categorySeries>
                            <seriesExpression><![CDATA[$F{type}]]></seriesExpression>
                            <categoryExpression><![CDATA[$F{time}]]></categoryExpression>
                            <valueExpression><![CDATA[$F{kwh}]]></valueExpression>
                        </categorySeries>
                    </categoryDataset>
                    <linePlot>
                        <plot backgroundAlpha="1.0" labelRotation="90.0"/>
                        <categoryAxisFormat labelRotation="90.0">
                            <axisFormat labelColor="#000000" tickLabelColor="#000000" tickLabelMask="asdf" axisLineColor="#000000">
                                <labelFont>
                                    <font size="10"/>
                                </labelFont>
                                <tickLabelFont>
                                    <font size="6"/>
                                </tickLabelFont>
                            </axisFormat>
                        </categoryAxisFormat>
                        <valueAxisFormat>
                            <axisFormat labelColor="#000000" tickLabelColor="#000000" axisLineColor="#000000"/>
                        </valueAxisFormat>
                    </linePlot>
                </lineChart>
            </band>
        </groupHeader>
    </group>
</jasperReport>

This report should give me charts with all fixed y-axis from 1..30 when I feed it with data like:

day|type|dateAsString|weekdayAsString|time|kwh
1|Data|01.12.2018|Samstag|00:00|2.501
1|Data|01.12.2018|Samstag|00:15|2.679
1|Data|01.12.2018|Samstag|00:30|2.93
1|Data|01.12.2018|Samstag|00:45|2.363
1|Data|01.12.2018|Samstag|01:00|2.589
1|Data|01.12.2018|Samstag|01:15|2.423
1|Data|01.12.2018|Samstag|01:30|2.531
1|Data|01.12.2018|Samstag|01:45|2.976
1|Data|01.12.2018|Samstag|02:00|2.369
1|Data|01.12.2018|Samstag|02:15|2.636
1|Data|01.12.2018|Samstag|02:30|2.391
1|Data|01.12.2018|Samstag|02:45|2.667
1|Data|01.12.2018|Samstag|03:00|2.88
1|Min|01.12.2018|Samstag|00:00|2.154
1|Min|01.12.2018|Samstag|00:15|2.093
1|Min|01.12.2018|Samstag|00:30|2.052
1|Min|01.12.2018|Samstag|00:45|2.126
1|Min|01.12.2018|Samstag|01:00|2.139
1|Min|01.12.2018|Samstag|01:15|2.171
1|Min|01.12.2018|Samstag|01:30|2.162
1|Min|01.12.2018|Samstag|01:45|2.178
1|Min|01.12.2018|Samstag|02:00|2.049
1|Min|01.12.2018|Samstag|02:15|2.033
1|Min|01.12.2018|Samstag|02:30|2.034
1|Min|01.12.2018|Samstag|02:45|2.129
1|Min|01.12.2018|Samstag|03:00|2.159
1|Average|01.12.2018|Samstag|00:00|2.5004375
1|Average|01.12.2018|Samstag|00:15|2.2665
1|Average|01.12.2018|Samstag|00:30|2.2095624999999997
1|Average|01.12.2018|Samstag|00:45|2.309
1|Average|01.12.2018|Samstag|01:00|2.5692500000000003
1|Average|01.12.2018|Samstag|01:15|2.364
1|Average|01.12.2018|Samstag|01:30|2.26425
1|Average|01.12.2018|Samstag|01:45|2.4954375
1|Average|01.12.2018|Samstag|02:00|2.39825
1|Average|01.12.2018|Samstag|02:15|2.2420625000000003
1|Average|01.12.2018|Samstag|02:30|2.2153125
1|Average|01.12.2018|Samstag|02:45|2.4844999999999997
1|Average|01.12.2018|Samstag|03:00|2.3979375
1|Max|01.12.2018|Samstag|00:00|2.814
1|Max|01.12.2018|Samstag|00:15|2.759
1|Max|01.12.2018|Samstag|00:30|2.93
1|Max|01.12.2018|Samstag|00:45|2.777
1|Max|01.12.2018|Samstag|01:00|2.996
1|Max|01.12.2018|Samstag|01:15|2.933
1|Max|01.12.2018|Samstag|01:30|2.573
1|Max|01.12.2018|Samstag|01:45|2.976
1|Max|01.12.2018|Samstag|02:00|2.805
1|Max|01.12.2018|Samstag|02:15|2.846
1|Max|01.12.2018|Samstag|02:30|2.574
1|Max|01.12.2018|Samstag|02:45|2.82
1|Max|01.12.2018|Samstag|03:00|2.945
2|Data|02.12.2018|Sonntag|00:00|2.264
2|Data|02.12.2018|Sonntag|00:15|2.555
2|Data|02.12.2018|Sonntag|00:30|2.382
2|Data|02.12.2018|Sonntag|00:45|2.586
2|Data|02.12.2018|Sonntag|01:00|2.754
2|Data|02.12.2018|Sonntag|01:15|2.406
2|Data|02.12.2018|Sonntag|01:30|2.9
2|Data|02.12.2018|Sonntag|01:45|2.751
2|Data|02.12.2018|Sonntag|02:00|2.489
2|Data|02.12.2018|Sonntag|02:15|2.459
2|Data|02.12.2018|Sonntag|02:30|2.624
2|Data|02.12.2018|Sonntag|02:45|2.93
2|Data|02.12.2018|Sonntag|03:00|2.412
2|Min|02.12.2018|Sonntag|00:00|2.238
2|Min|02.12.2018|Sonntag|00:15|2.361
2|Min|02.12.2018|Sonntag|00:30|2.058
2|Min|02.12.2018|Sonntag|00:45|1.781
2|Min|02.12.2018|Sonntag|01:00|2.148
2|Min|02.12.2018|Sonntag|01:15|2.136
2|Min|02.12.2018|Sonntag|01:30|2.04
2|Min|02.12.2018|Sonntag|01:45|1.814
2|Min|02.12.2018|Sonntag|02:00|1.92
2|Min|02.12.2018|Sonntag|02:15|2.064
2|Min|02.12.2018|Sonntag|02:30|2.237
2|Min|02.12.2018|Sonntag|02:45|2.1
2|Min|02.12.2018|Sonntag|03:00|1.772
2|Average|02.12.2018|Sonntag|00:00|2.4595000000000002
2|Average|02.12.2018|Sonntag|00:15|2.4008125000000002
2|Average|02.12.2018|Sonntag|00:30|2.377375
2|Average|02.12.2018|Sonntag|00:45|2.2220625
2|Average|02.12.2018|Sonntag|01:00|2.388
2|Average|02.12.2018|Sonntag|01:15|2.3143124999999998
2|Average|02.12.2018|Sonntag|01:30|2.3325
2|Average|02.12.2018|Sonntag|01:45|2.4194375
2|Average|02.12.2018|Sonntag|02:00|2.3320625
2|Average|02.12.2018|Sonntag|02:15|2.2799375
2|Average|02.12.2018|Sonntag|02:30|2.3516250000000003
2|Average|02.12.2018|Sonntag|02:45|2.53775
2|Average|02.12.2018|Sonntag|03:00|2.2266250000000003
2|Max|02.12.2018|Sonntag|00:00|3.141
2|Max|02.12.2018|Sonntag|00:15|2.555
2|Max|02.12.2018|Sonntag|00:30|2.627
2|Max|02.12.2018|Sonntag|00:45|2.897
2|Max|02.12.2018|Sonntag|01:00|2.754
2|Max|02.12.2018|Sonntag|01:15|2.526
2|Max|02.12.2018|Sonntag|01:30|2.912
2|Max|02.12.2018|Sonntag|01:45|2.751
2|Max|02.12.2018|Sonntag|02:00|3.002
2|Max|02.12.2018|Sonntag|02:15|2.589
2|Max|02.12.2018|Sonntag|02:30|2.624
2|Max|02.12.2018|Sonntag|02:45|2.937
2|Max|02.12.2018|Sonntag|03:00|2.412

shouldn't it? well it doesn't and I don't understand why?

Alex K
  • 22,315
  • 19
  • 108
  • 236
roediGERhard
  • 163
  • 1
  • 12

2 Answers2

2

These chart customizers are to be used from JasperSoft Studio I believe version 6.3.1 and above.

Normally you should click on chart and in Properties>>Chart select "Add", when selecting a customizer a dialog will open where you can input your data.

Jasper Reports Studio

Anyway the correct properties in jrxml are:

 <chart evaluationTime="Group" evaluationGroup="DayGroup">
    <reportElement x="0" y="0" width="800" height="500" uuid="2f4f1b7b-7b71-4440-80b0-3ab75e84196f">
        <property name="net.sf.jasperreports.customizer.class.rangeAxis" value="net.sf.jasperreports.customizers.axis.RangeAxisCustomizer"/>
        <property name="net.sf.jasperreports.customizer.rangeAxis.minValue" value="1.0"/>
        <property name="net.sf.jasperreports.customizer.rangeAxis.maxValue" value="30.0"/>
        <property name="net.sf.jasperreports.customizer.rangeAxis.tickUnit" value="1.0"/>
    </reportElement>
    ....
</chart>

My output with a similar setting is:

output

Which is what I would expect, range axis starting at value 1, ending at value 30, with a tick range of 1.

Petter Friberg
  • 21,252
  • 9
  • 60
  • 109
  • It works with your properties. Many thanks, i was looking for that for several hours till now. Regarding your recommendations for the jaspersoft studio....i do not use any studio anymore, as i've experienced some issues with it (properties like the margin was not set correctly although i used the dialog from the GUI several times and set it to a correct value. since then i am hard coding in the jrxml file ;) But thanks for the answer. This was the final touch to my report :) – roediGERhard Jan 24 '19 at 13:28
0

I had a similar issue with a bubble chart where some bubbles on the edges were only partially drawn. In addition to the properties, we can change the scales with the following tags:

  • domainAxisMinValueExpression
  • domainAxisMaxValueExpression
  • rangeAxisMinValueExpression
  • rangeAxisMaxValueExpression

Both bubble chart & line chart have these tags. In case of the bubble chart, this is the way to do it:

<bubblePlot>
    <plot/>
    <xAxisLabelExpression><![CDATA["Quantity"]]></xAxisLabelExpression>
    <xAxisFormat>
        <axisFormat/>
    </xAxisFormat>
    <yAxisLabelExpression><![CDATA["Price"]]></yAxisLabelExpression>
    <yAxisFormat>
        <axisFormat/>
    </yAxisFormat>
    <domainAxisMinValueExpression><![CDATA[0]]></domainAxisMinValueExpression>
    <domainAxisMaxValueExpression><![CDATA[80]]></domainAxisMaxValueExpression>
    <rangeAxisMinValueExpression><![CDATA[0]]></rangeAxisMinValueExpression>
    <rangeAxisMaxValueExpression><![CDATA[1000]]></rangeAxisMaxValueExpression>
</bubblePlot>

Check the schema reference for which charts support these tags: http://jasperreports.sourceforge.net/schema.reference.html

Jan Bodnar
  • 10,969
  • 6
  • 68
  • 77