Reputation: 60
Hello !
I need to create a report like the attachment shows with Jasper Reports.
I've tried it with line chart. Result : line chart expects 2 number type field for axises.
I've tried it with Time series. Result : time series expect 1 number and 1 date type field for axises.
I have to use dates, so I need a chart type what can handle dates.
Any suggestion how can I solve this ? I've tried Google at least 10 hour. Now I'm very desperated.
Thanks !
Upvotes: 0
Views: 1523
Reputation: 60
I think I've solved my problem. I've written a customizer class :
package com.test;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import net.sf.jasperreports.engine.JRChart;
import net.sf.jasperreports.engine.JRChartCustomizer;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.DateAxis;
import org.jfree.chart.axis.DateTickUnit;
import org.jfree.chart.plot.XYPlot;
public class TrendCustomizer implements JRChartCustomizer {
public void customize(JFreeChart chart, JRChart jasperChart) {
DateAxis xAxis = new DateAxis();
DateAxis yAxis = new DateAxis();
DateTickUnit unit = null;
unit = new DateTickUnit(DateTickUnit.MONTH, 6);
DateFormat chartFormatter = new SimpleDateFormat("yyyy.MM.dd");
xAxis.setDateFormatOverride(chartFormatter);
xAxis.setTickUnit(unit);
yAxis.setDateFormatOverride(chartFormatter);
yAxis.setTickUnit(unit);
((XYPlot)chart.getPlot()).setDomainAxis(xAxis);
((XYPlot)chart.getPlot()).setRangeAxis(yAxis);
}
}
Upvotes: 1