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

1

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

 

jasperNewb21's picture
Joined: Jul 12 2012 - 5:10am
Last seen: 6 years 5 months ago
Hi, did you ever find a solution to this? I am looking for one myself. Thanks!
rsteier - 6 years 4 months ago

Hi, I have a similar requirement. I am getting a JSON string from UI and I want to convert and use this as JSONDataSource. Can amyone please guide how this can be done?

sindhu.sankaran - 5 years 10 months ago
Hi I am a new bee to Jasper report. I have a similar requirement. I want to pass dynamic json to jasperreport, from a java class. Please provide any direction how this can be done? Thanks
lipiden8 - 5 years 1 month ago

0 Answers:

No answers yet
Feedback
randomness