Jump to content
Changes to the Jaspersoft community edition download ×

Jasper - how to dynamically create chart from JSON or XML fields


Recommended Posts

Up until now, I've been using a database connection to populate the data in my reports, which has worked well.  Now I am struggling to get it working with a different type of input.

Ultimately, my goal is to have a Java process which generates an array of values, which it then passes to Jasper to generate a chart in an XLS file.  For example, I may pass in {[0,0],[1,1],[2,2],[3,3]} if I wanted Jasper to generate a straight line.  Each time my Java process runs, the input data will be different, however the structure of the data will be the same.  I am looking into how I can pass in the data using JSON, however I am not tied to that solution.  What is the best way to acheive my goal?  JSON?  XML?  A custom Java class?

As a first step, I've tried to get the Northwind.Customers example to work.  I created a new report in iReport that reads the northwind.json file and that works okay.  However, when I try to call it from Java, no data populates.  What am I doing wrong?

JasperDesign jasperDesign = JRXmlLoader.load("path\to\designFile");
JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
JsonDataSource jsonDataSource = new JsonDataSource(new File("path\to\northwind.json"));
JasperPrint  jasperPrintNew  = JasperFillManager.fillReport(jasperReport, h2, jsonDataSource);

Thank you


Link to comment
Share on other sites

  • 1 month later...
  • Replies 3
  • Created
  • Last Reply

Top Posters In This Topic

  • 5 months later...
  • 9 months later...

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...