Jump to content
JasperReports Library 7.0 is now available ×

Custom DataSource


aronrodrigues

Recommended Posts

Hi. I'm a really new user of Jasper + iReport and I'm having some troubles because I don´t have a JDBC source. We here use XML files that are loaded in Objects. I need to make a graph with those objects data.
Here is my custom data source:
 

Code:
package report;import java.util.HashMap;import java.util.Iterator;import java.util.Map;import net.sf.jasperreports.engine.JRDataSource;import net.sf.jasperreports.engine.JRException;import net.sf.jasperreports.engine.JRField;public class CustomJRDataSource implements JRDataSource {    private Map data;    private Iterator keyIterator;    private String key;    public CustomJRDataSource() {			this.data = new HashMap();	this.data.put("200600501", new Double(1.1230));	this.data.put("200600603", new Double(2.1234));	this.data.put("200600706", new Double(3.1241));	this.data.put("200600801", new Double(1));	this.keyIterator = data.keySet().iterator();	    }    public boolean next() throws JRException {				boolean result = false;			if (this.keyIterator.hasNext()) {	    this.key = this.keyIterator.next();				    result = true;				}        else {			    this.key = null;			}        return result;    }    public Object getFieldValue(JRField arg0) throws JRException {	Object result = null;	if ("KEY".equals(arg0.getName())) {	    result = this.key;	} else {	    result = this.data.get(this.key).toString();	}	return result;    }},>,>[/code]			


this datasource in my java program fills the report and the list of numbers works. But in the iReport, returns null and a ClassCastException because it can´t cast from null.

I need to make a graph with one line with the values in that data source. All documentation and samples that I found uses jdbc. Can anyone helpme?

Link to comment
Share on other sites

  • Replies 1
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...