2

My JAVA project needs to generate PDF with chart as shown below. I managed to get similar chart with Jasper report. However, I am not able to achieve following things though Jasper report.

  1. Print number inside bubble
  2. String in x-axis

This is what I get : enter image description here

This is what I want enter image description here

Request your suggestion to achieve the items above through Jasper report or any other suitable java tool available for this chart.

Jreport:

public class JReport {

public static void main(String[] args) throws Exception {
    List<Data> dataList = new ArrayList<Data>();
    dataList.add(new Data("A", 1, 3d, 0.3));
    dataList.add(new Data("A", 2d, 4d, 0.3));
    dataList.add(new Data("A", 2d, 3d, 0.3));
    dataList.add(new Data("B", 2d, 4d, 0.3));
    dataList.add(new Data("A", 2d, 3d, 0.4));
    dataList.add(new Data("B", 5d, 6d, 0.4));
    dataList.add(new Data("B", 4d, 3d, 0.3));
    dataList.add(new Data("B", 2d, 5d, 0.3));
    dataList.add(new Data("C", 5d, 6d, 0.3));
    dataList.add(new Data("C", 2d, 3d, 0.3));
    dataList.add(new Data("C", 4d, 5d, 0.4));
    String templateFile = "C:\\WS\\bubble.jrxml";
    File file = new File(templateFile);  
    JasperDesign design = JRXmlLoader.load(file);
    JasperReport report = JasperCompileManager.compileReport(design);
    Map parameter = new HashMap();
    JasperPrint print = JasperFillManager.fillReport(report, parameter, new JRBeanCollectionDataSource(dataList));
    JasperExportManager.exportReportToPdfFile(print, "D:/temp/bubble_chart.pdf");
}

}

Data.java

public class Data {
private String name;
private double x;
private double y;
private double z;

public Data(String name, double x, double y, double z) {
    this.name = name;
    this.x = x;
    this.y = y;
    this.z = z;
}
// getter, setter

Bubble.jrxml:

    <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE jasperReport PUBLIC "-//JasperReports//DTD Report Design//EN" 
"http://jasperreports.sourceforge.net/dtds/jasperreport.dtd">
<jasperReport name="BubbleChartReport" columnCount="2" pageWidth="595" pageHeight="842" columnWidth="270" columnSpacing="15" leftMargin="20" rightMargin="20" topMargin="30">
  <property name="ireport.zoom" value="1.0"/>
  <property name="ireport.x" value="0"/>
  <property name="ireport.y" value="0"/>
  <field name="name" class="java.lang.String"/>
  <field name="x" class="java.lang.Double"/>
  <field name="y" class="java.lang.Double"/>
  <field name="z" class="java.lang.Double"/>
  <pageHeader>
     <band height="203">
         <bubbleChart>
             <chart evaluationTime="Report" >
                 <reportElement positionType="Float" x="0" y="2" width="555" height="197"/>
                 <chartTitle/>
                 <chartSubtitle/>
                 <chartLegend/>
             </chart>
             <xyzDataset>
                 <xyzSeries>
                     <seriesExpression><![CDATA[$F{name}]]></seriesExpression>
                     <xValueExpression><![CDATA[$F{x}]]></xValueExpression>
                     <yValueExpression><![CDATA[$F{y}]]></yValueExpression>
                     <zValueExpression><![CDATA[$F{z}]]></zValueExpression>
                 </xyzSeries>
             </xyzDataset>
             <bubblePlot scaleType="RangeAxis">
                 <plot/>
                 <xAxisFormat>
                     <axisFormat/>
                 </xAxisFormat>
                 <yAxisFormat>
                     <axisFormat/>
                 </yAxisFormat>
             </bubblePlot>
         </bubbleChart>
     </band>
  </pageHeader>
</jasperReport>
  • If you are not bound to use jasper reports, then check out punch cards format (https://stackoverflow.com/questions/9278456/using-highcharts-js-to-create-a-punch-card-style-graph) . You can use highcharts for it. And second point, do not use stackoverflow like homework solving place. People will only be interested to answer you when you ask them specific and sensible questions. – Siddharth Jun 15 '17 at 09:43
  • @Siddharth, Thanks for your suggestion. I dont understand how do your term my question as home work. If you try to understand my question, "I managed to get chart that I require however, two things that I am not able to achieve", Thats where I asked for help. – Naveen Kumar Jun 15 '17 at 09:47
  • @Siddharth, Moreover, I asked about report generation from JAVA not from HTML. You suggested HTML. Hope you will read my post again clearly. – Naveen Kumar Jun 15 '17 at 09:53
  • 1.What I mean is, go ahead and add the code snippets so that people get the area where to help you. 2. Java project does not mean you cannot have HTML modules in it. Moreover, Jasper itself supports highcharts module http://community.jaspersoft.com/wiki/advanced-formatting-new-html5-charts . ...... and stay a bit longer on stackoverflow and you will get what I mean. – Siddharth Jun 15 '17 at 10:01
  • 1. Agree to this, I have added code snippet just now. 2. Basically, it is back end thing. I need to generate report in the server itself (100+ reports at a time), hence HTML will not be a good choice. So, I prefer a plain JAVA util for my requirement. – Naveen Kumar Jun 15 '17 at 10:16

0 Answers0