Jump to content
Changes to the Jaspersoft community edition download ×

Not able to generate a bar chart


Recommended Posts

Hi ,

I am new to Jasper Reports and i am trying to generate a bar chart with data coming from my data source but am getting stuck at a place. I am getting exception which i am not able to resolve. Cant figure out where am i going wrong . Can someone pls help.

Exception in thread "main" java.lang.NullPointerException at net.sf.jasperreports.charts.fill.JRFillCategoryDataset.customIncrement(JRFillCategoryDataset.java:136) at net.sf.jasperreports.engine.fill.JRFillElementDataset.increment(JRFillElementDataset.java:134)

Heres the java file.


public class JasperReportsIntro


public static void main(String[] args)


JasperReport jasperReport;

JasperPrint jasperPrint;



jasperReport = JasperCompileManager.compileReport("/home/arpana/work/bccms/src/com/bc/reports/rep/jasperreports_demo.jrxml");

String columnNames[]={"FIELD1","VALUE"};

ArrayList arrayList = new ArrayList<ArrayList<Double>>();

List<Double> dataArray = new ArrayList<Double>();






List<Double> dataArray1 = new ArrayList<Double>();





jasperPrint = JasperFillManager.fillReport(jasperReport, new HashMap(), new JRTableModelDataSource(new DataSource(columnNames, arrayList)));

JasperExportManager.exportReportToPdfFile(jasperPrint, "/home/arpana/bar_report.pdf");

System.out.println("Successfully exported to PDF");


catch (JRException e)







Heres the jrxml file :

<?xml version="1.0"?>

<!DOCTYPE jasperReport

PUBLIC "-//JasperReports//DTD Report Design//EN"



<jasperReport name="Simple_Report">


<parameter name="VALUE_HEADER_P" isForPrompting="false" class="java.lang.String"/>


<field name="FIELD1" class="java.lang.Double">


<field name="VALUE" class="java.lang.Double">



<variable name="SumFirstGroup" class="java.lang.Double">




<group name="FirstGroup" isStartNewColumn="false" isReprintHeaderOnEachPage="false" minHeightToStartNewPage="25">





<band height="120">


<reportElement x="80" y="0" width="200" height="20"/>

<text><![CDATA[Hello World!]]></text>



<chart evaluationTime="Report">

<reportElement positionType="Float" x="0" y="35" width="540" height="75"/>



<dataset incrementType="Group" incrementGroup="FirstGroup"/>




<valueExpression>new Double($F{VALUE}.doubleValue() / 2d)</valueExpression>



<barPlot isShowTickMarks="true" isShowTickLabels="true">








And finally the data source file.

public class DataSource extends AbstractTableModel



private String[] columnNames = null;;

private String[] columnDisplayNames = null;



* ArrayList of ArrayLists


private ArrayList<ArrayList> data = null;


public DataSource(String[] columns, ArrayList records)


columnNames = columns;

data = records;



public void setColumnDisplayNames(String[] displayNames)


columnDisplayNames = displayNames;



public String[] getColumnDisplayNames()


return columnDisplayNames;



public int getColumnCount()


return this.columnNames.length;



public String getColumnName(int columnIndex)


return this.columnNames[columnIndex];



public int getRowCount()


return this.data.size();



public Object getValueAt(int rowIndex, int columnIndex)


ArrayList record = (ArrayList) data.get(rowIndex);

return record.get(columnIndex);



public ArrayList getData()


return data;




Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

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