1

I have a XY Line Chart in JasperReports and I´m using a range in my Chart for display the Months, currently i´m using this configuration and show the values from 1 to 12 in X Line:

Image of currently chart

<?xml version="1.0" encoding="UTF-8"?>
<property name="net.sf.jasperreports.customizer.class.1" value="net.sf.jasperreports.customizers.axis.DomainAxisCustomizer"/>
                    <property name="net.sf.jasperreports.customizer.1.tickUnit" value="1.0"/>
                    <propertyExpression name="net.sf.jasperreports.customizer.1.minValue"><![CDATA["1"]]></propertyExpression>
                    <propertyExpression name="net.sf.jasperreports.customizer.1.maxValue"><![CDATA["12"]]></propertyExpression>

but I need show the abbreviation of the months, like this:

1 - JAN, 2 - FEB, 3 - MAR, ...

Is there a better way to do this?

Alex K
  • 22,315
  • 19
  • 108
  • 236

1 Answers1

0

You can implement your own domain axis customizer like this:

public class DomainAxisWithMonthsCustomizer extends JRAbstractChartCustomizer {
    @Override
    public void customize(JFreeChart chart, JRChart jasperChart) {
        XYPlot plot = chart.getXYPlot();
        String[] shortMonths = new DateFormatSymbols().getShortMonths();
        SymbolAxis domainAxis = new SymbolAxis("Month",
                IntStream.rangeClosed(1, 12)
                        .mapToObj(m -> m + " - " + shortMonths[m - 1].toUpperCase())
                        .toArray(String[]::new));
        plot.setDomainAxis(domainAxis);
    }
}

And use it in your report template:

<chart customizerClass="my.project.report.DomainAxisWithMonthsCustomizer">
...
</chart>
cgrim
  • 4,890
  • 1
  • 23
  • 42
  • Thanks for answer me. Is it possible do this in Tibco Jasper Reports? – Ítalo Duarte Sep 27 '18 at 08:43
  • I tested that with JasperSoft Jasper Reports 6.7.0. Which version are you using? That example class must be compiled by `javac`, then create JAR archive and add it to classpath of application where you want to run the report (JasperStudio, your custom application, JasperReports Server). – cgrim Sep 27 '18 at 09:17
  • The solution works fine, I did some configuration in Jasper to work with java classes, and after applied your solution. Thanks a lot. – Ítalo Duarte Sep 27 '18 at 10:13