subashmy Posted December 10, 2012 Share Posted December 10, 2012 How to write a customizer class for bar chart, pie chart ?? (that should handle no data in subdataset & show proper No Data message) How to upload it to ireport ?? Anyone, please give some clear explanation on it.. please Link to comment Share on other sites More sharing options...
augarte Posted December 10, 2012 Share Posted December 10, 2012 Hi, First of all you need to create a customize class. The following is an example of a Line Chart customizer: package com.almis.awe.chartcustomizer; import java.awt.Color;import java.awt.BasicStroke; import net.sf.jasperreports.engine.JRChart;import net.sf.jasperreports.engine.JRChartCustomizer; import org.jfree.chart.JFreeChart;import org.jfree.data.category.*;import org.jfree.chart.renderer.category.LineAndShapeRenderer; import java.util.HashMap;/** * * @author augarte */public class AweLineChartCustomizer implements JRChartCustomizer{ public static HashMap engGroupColor = new HashMap(); static { engGroupColor.put("A", new Color(0xE4, 0x1B, 0x1B)); engGroupColor.put("B", new Color(0xF1, 0xAB, 0x10)); } public void customize(JFreeChart chart, JRChart jasperChart) { // Category Plot: most commonly used to display bar chart // BarRenderer: create bar charts from data in a category dataset LineAndShapeRenderer renderer = (LineAndShapeRenderer) chart.getCategoryPlot().getRenderer(); // Method required for reading the dataset. // Table of values that can be accessed using row and column keys. CategoryDataset cd = chart.getCategoryPlot().getDataset(); // Row gives the series expression int rc = cd.getRowCount(); for (int i = 0; i < rc; i++) { renderer.setSeriesStroke(i, new BasicStroke(2f)); } } } Then you need to add it to iReport. What I do is to add all my classes to a jar file and the add this file to iReport classpath (Tools->Options->iReport, inside the "classpath" tab). The last step is to say to the chart to use this customize. If you select the chart (inside your report), in the right side you will see that there is a property "customizer class". You have to set the customizer here, in my case. com.almis.awe.chartcustomizer.AweLineChartCustomizer Hope this helps. Best regards, Aitor Link to comment Share on other sites More sharing options...
subashmy Posted December 10, 2012 Author Share Posted December 10, 2012 Thanks augarte, it helps... I wil get back to you on this.. meanwhile can you tellme how to deal with the following type of error??Source text : ' Summary Total # of calls: ' + new DecimalFormat("#,000").format($F{totalCt}) + ' Total minutes: ' + new DecimalFormat("#,000").format($F{totalMin})net.sf.jasperreports.engine.fill.JRExpressionEvalException: Error evaluating expression : Source text : ' Summary Total # of calls: ' + new DecimalFormat("#,000").format($F{totalCt}) + ' Total minutes: ' + new DecimalFormat("#,000").format($F{totalMin}) ...........I couldn't figure out how to resolve this... I have a report & four datasets, in two of the datasets, the data is coming as blank... so how should I deal with that??? Link to comment Share on other sites More sharing options...
augarte Posted December 10, 2012 Share Posted December 10, 2012 What is that exactly? Where are you adding the following expression?' Summary Total # of calls: ' + new DecimalFormat("#,000").format($F{totalCt}) + ' Total minutes: ' + new DecimalFormat("#,000").format($F{totalMin})Something is wrong here with this expression. If you check the DecimalFormat javadoc you will see that there is not any "format" function with one parameter: http://docs.oracle.com/javase/6/docs/api/java/text/DecimalFormat.htmlSo you have at least one error in this expression. Anyway, it would be easier to help you if you explain what do you want to do. From the expression I guess you need to add some data using "HTML markup" but don't know exactly what you want. Regards,Aitor Link to comment Share on other sites More sharing options...
subashmy Posted December 10, 2012 Author Share Posted December 10, 2012 Hi augarte,My main report query is...select COUNT(*) as totalCt ,SUM(callDurationTotalMinutes) as totalMin from vw_DMAProductionCalls where callType in ('VMR', 'Pt-pt outbound') and targetEndpoint <> 'gatekeeper-monitoring-check' and callStartMonth = $P{month} and callStartYear = $P{year} & my variable expression is...' Summary Total # of calls: ' + new DecimalFormat("#,000").format($F{totalCt}) + ' Total minutes: ' + new DecimalFormat("#,000").format($F{totalMin}) This expression works well if I input '3 to 12' as value to $P{month}, but the above error comes if value is '1 or 2' as it doesn't have any data for january n february...I have 4 other datasets, but the error occurs in the above expression only for 1,2 months..Please help me out.. Regards,Subash. Link to comment Share on other sites More sharing options...
mdahlman Posted December 11, 2012 Share Posted December 11, 2012 You need to post this new question as a new question. Please don't post it as an answer. Link to comment Share on other sites More sharing options...
Solution augarte Posted December 11, 2012 Solution Share Posted December 11, 2012 Hi subashmy, What you can do is to create a variable that depends on the value of $F{totalCt} and another one that depends on $F{totalMin}, the "Variable Expression" should be as follows: $F{totalCt} == null ? Double.valueOf("0.0") : $F{totalCt} --> For $V{TotalCt} variable$F{totalMin} == null ? Double.valueOf("0.0") : $F{totalMin} --> For $V{TotalMin} variableThis way, if the value of the fields is null you'll have 0.00 in the variable, and otherwise you'll have the same value you have in the field. The you should change the variable expression in orther to use variables instead of fields: ' SummaryTotal # of calls: ' + new DecimalFormat("#,000").format($V{totalCt}) + 'Total minutes: ' + new DecimalFormat("#,000").format($V{totalMin})Maybe there is an easier option but I think this should work for you. Let us know if you solve your problem.Hope this helps,Aitor Link to comment Share on other sites More sharing options...
subashmy Posted December 12, 2012 Author Share Posted December 12, 2012 Hey Aitor, I have integer for both fields, so I am using the following expression.. $F{totalCt} == null ? 0 : $F{totalCt} for variable $V{TotalCt} & similarly other expression also..but still Error evaluating expression.... Link to comment Share on other sites More sharing options...
augarte Posted December 12, 2012 Share Posted December 12, 2012 Hi, This works with Integer type field/variable: $F{totalCt} == null ? Integer.valueOf("0") : $F{totalCt} Link to comment Share on other sites More sharing options...
subashmy Posted December 12, 2012 Author Share Posted December 12, 2012 Oh.. thnx mdahlman.. I will do that next time I have figured out the problem is not with the expression, it is with the null data.. so I need to handle it in ireport or from database.. Link to comment Share on other sites More sharing options...
mark.torres Posted April 4, 2014 Share Posted April 4, 2014 This one worked for me..($V{member_id_MEASURE1} != 0 ? (new DecimalFormat(".00").format(($V{member_id_MEASURE1}/$V{member_id_MEASURE1_deny_reasons1_ALL}) * 100)) : 0 ) + "%"I added the new DecimalFormat(".00").format( calculations) the + "%" is to give it like a percent look. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now