scottward Posted November 9, 2006 Share Posted November 9, 2006 Hello, I need to customize a chart in my report. Just basic things like the range, line colors, position of legend, etc. I understand that I have to use JRChartCustomizer to do this. Unfortunately, I've never programmed a line of java in my life, although I've used other programming languages. As has been pointed out by others, there is no step by step guide for those who are computer literate, but not familiar with java. Over and over, I've read something like, "To customize a chart all you have to do is implement the JRChartCustomizer interface..." Unfortunately, there are still lots of gaps for me. So what I'd like to do is work out a step by step process for the non Java programmer. If you veteran programmers out there could help me along, it will benefit quite a few people I think. OK, here we go. From what I can see, I need to write a custom snippet of code that will modify certain aspects of my chart. You tell iReport which snippet of code is to be used by:a) right clicking on the chart and selecting "Chart Properties"b) entering the name of the JAR file that contains the snippet of code in the field marked: Customizer Class. This is where I get fuzzy! Based on various posts I've put together some java code that I think will stipulate the colors of the first 2 lines on my line chart. Its is called "LineChartCustomizer.java" and the contents are as follows: Code:import net.sf.jasperreports.engine.JRChartCustomizer; import net.sf.jasperreports.engine.JRChartDataset; import net.sf.jasperreports.engine.JRChartPlot; import net.sf.jasperreports.engine.JRChart; import org.jfree.chart.JFreeChart; import org.jfree.chart.renderer.category.BarRenderer; import org.jfree.chart.axis.CategoryLabelPositions; import java.awt.*; public class LineChartCustomizer implements JRChartCustomizer { public void customize(JFreeChart chart, JRChart jasperChart) { ChartRenderer renderer = (ChartRenderer) chart.getCategoryPlot().getRenderer(); renderer.setSeriesPaint(0, Color.green); renderer.setSeriesPaint(1, Color.orange); } } Please, advise if there are any problems in the code above. OK, I know this is all BASIC stuff for you Java programmers, but not for the rest of us. Apparently, creating a JAR file requires 2 commands from the command prompt:a) javac LineChartCustomizer.java (which will create LineChartCustomizer.class)b) jar cf LineChartCustomizer (which will create LineChartCustomizer.jar) Then, in iReport you go to Options->Class Path and tell iReport where the LineChartCustomizer.jar file is. Apparently, you can add a single jar file or an entire folder of jar files. Again, please correct my mistakes above. I haven't actually successfully made it through these steps yet! Here is where I am failing:When I run javac LineChartCustomizer.java, I get the following errors:C:Program FilesJasperSoftiReport-1.2.6>javac LineChartCustomizer.javaLineChartCustomizer.java:1: package net.sf.jasperreports.engine does not existimport net.sf.jasperreports.engine.JRChartCustomizer; ^LineChartCustomizer.java:2: package net.sf.jasperreports.engine does not existimport net.sf.jasperreports.engine.JRChartDataset; ^LineChartCustomizer.java:3: package net.sf.jasperreports.engine does not existimport net.sf.jasperreports.engine.JRChartPlot; ^LineChartCustomizer.java:4: package net.sf.jasperreports.engine does not existimport net.sf.jasperreports.engine.JRChart; ^LineChartCustomizer.java:5: package org.jfree.chart does not existimport org.jfree.chart.JFreeChart; ^LineChartCustomizer.java:6: package org.jfree.chart.renderer.category does not existimport org.jfree.chart.renderer.category.BarRenderer; ^LineChartCustomizer.java:7: package org.jfree.chart.axis does not existimport org.jfree.chart.axis.CategoryLabelPositions; ^LineChartCustomizer.java:11: cannot find symbolsymbol: class JRChartCustomizerpublic class LineChartCustomizer implements JRChartCustomizer { ^LineChartCustomizer.java:13: cannot find symbolsymbol : class JFreeChartlocation: class LineChartCustomizer public void customize(JFreeChart chart, JRChart jasperChart) { ^LineChartCustomizer.java:13: cannot find symbolsymbol : class JRChartlocation: class LineChartCustomizer public void customize(JFreeChart chart, JRChart jasperChart) { ^LineChartCustomizer.java:15: cannot find symbolsymbol : class ChartRendererlocation: class LineChartCustomizer ChartRenderer renderer = (ChartRenderer) chart.getCategoryPlot().getRenderer(); ^LineChartCustomizer.java:15: cannot find symbolsymbol : class ChartRendererlocation: class LineChartCustomizer ChartRenderer renderer = (ChartRenderer) chart.getCategoryPlot().getRenderer(); ^12 errorsC:Program FilesJasperSoftiReport-1.2.6> Clearly, Java has no idea where all the classes that I am importing are located. Without them, the creation of the class file fails. So here are my questions:1) What do I need to do to successfully compile the class file?2) After that, do I simply type "jar cf LineChartCustomizer" and the jar file will be ready to go? Or is there more setup required? Thanks for helping out the non-programmers who love iReport and JasperReports! Sincerely, Scott Link to comment Share on other sites More sharing options...
scottward Posted November 10, 2006 Author Share Posted November 10, 2006 Can anybody shed some light on this? It'd be a great help to quite a few of us, I think. Scott Link to comment Share on other sites More sharing options...
scottward Posted November 14, 2006 Author Share Posted November 14, 2006 OK, if responses aren't coming because I should ask the question somewhere else, please advise. Or if I need to ask it differently, let me know. Scott Link to comment Share on other sites More sharing options...
borut.hadzialic Posted November 15, 2006 Share Posted November 15, 2006 Hi. You need to use javac's -classpath or -cp option to inlcude some .jar files in the classpath. These jars must contain all classes your code references. I don't exactly know which .jars you need to include, but there is a big chance that you only need jasperreports-1.2.x.jar. Open an editor and make a .bat / .sh script that will call javac with -classpath /some/path/jasperreports-1.2.x.jar:/some/path/someOther.jar... (making a script is good in case you need to change and recompile your code later.. you know that already.) Link to comment Share on other sites More sharing options...
atanupanda Posted February 5, 2007 Share Posted February 5, 2007 Post edited by: atanupanda, at: 2007/02/05 12:15 Link to comment Share on other sites More sharing options...
atanupanda Posted February 6, 2007 Share Posted February 6, 2007 HiThis is Atanu. I am very new in ireport and also in java environment. In the ireport I have designed a template .like this.please look on attach filesize=150C:Documents and SettingsAtanuMy Documentsgraph.jpeg[/img]Now I want to plot a line graph on the basis of the each data like t1 t2 ---t5 and lcl, ucl, actual value for each row.That I have done. Now my problem is that I have to change the color of points of t1 t2 ---t5 on the basis of Lcl and Ucl . If the value of t1 ,or t2 or ----t5 are between Ucl and Lcl the color will be blue. And if it out side of Lcl and Ucl then it will be red..I want the following figure. Where the upper bold line is Ucl and lower bold line isLclsize=150C:Documents and SettingsAtanuMy Documentsdata.jpeg[/img] Actually I have got a information that for that I have to write a customizer class for chart. Also I have write it . Code:import net.sf.jasperreports.engine.*;import net.sf.jasperreports.view.JasperViewer;import net.sf.jasperreports.engine.JREmptyDataSource;import java.util.*;import java.sql.DriverManager;import java.sql.Connection;import java.sql.SQLException;import net.sf.jasperreports.engine.JRAbstractChartCustomizer;import javax.sql.*;import org.jfree.chart.axis.CategoryAxis;import org.jfree.chart.plot.CategoryPlot;import org.jfree.chart.renderer.category.*;import org.jfree.chart.renderer.*;import org.jfree.chart.ChartRenderingInfo;import org.jfree.chart.renderer.category.BarRenderer;import org.jfree.chart.renderer.category.LevelRenderer;import org.jfree.chart.renderer.category.LayeredBarRenderer;import java.sql.DriverManager;import java.sql.SQLException;import java.sql.Connection;import java.util.HashMap;import java.util.Map;import java.lang.String;import net.sf.jasperreports.engine.JRException;import net.sf.jasperreports.engine.JasperExportManager;import net.sf.jasperreports.view.JasperViewer;import net.sf.jasperreports.engine.xml.JRXmlLoader;import net.sf.jasperreports.engine.JasperCompileManager;import net.sf.jasperreports.engine.JasperFillManager;import net.sf.jasperreports.engine.JasperPrint;import net.sf.jasperreports.engine.design.JasperDesign;import net.sf.jasperreports.engine.JasperReport;import net.sf.jasperreports.engine.JRChartDataset; import net.sf.jasperreports.engine.JRChartPlot; import org.jfree.chart.renderer.category.BarRenderer3D; import org.jfree.chart.renderer.category.LineAndShapeRenderer;import org.jfree.chart.axis.CategoryLabelPositions;import org.jfree.chart.renderer.category.LineRenderer3D;import java.awt.*;import net.sf.jasperreports.engine.JRChart;import net.sf.jasperreports.engine.JRChartCustomizer;import org.jfree.chart.JFreeChart;import net.sf.jasperreports.engine.*;import java.awt.Color;import net.sf.jasperreports.engine.JRChart;import net.sf.jasperreports.engine.JRChartCustomizer;import org.jfree.chart.JFreeChart;import org.jfree.chart.axis.CategoryAxis;import org.jfree.chart.axis.CategoryLabelPositions;import org.jfree.chart.plot.CategoryPlot;import org.jfree.chart.renderer.category.BarRenderer3D;import java.lang.Object; public class LineChartCustomizer extends JRAbstractChartCustomizer { public void customize(JFreeChart chart, JRChart jasperChart) { LineAndShapeRenderer renderer = (LineAndShapeRenderer) chart.getCategoryPlot().getRenderer(); renderer.setSeriesPaint(1, Color.green); renderer.setSeriesPaint(4, Color.orange); chart.setTitle("Setting the title "«»); } }Now this customize class ok running successfully with creating jar files.Now I want to create a logic to check the value of t1 t2 t3 t5 with respect to UCL and LCL. How can I fetch data from report.Or is there any other way to do this.Is there any way to pass value from iReport to customizer class ? What should I do. Please please help me. It’s urget for me. Any help would be greatly appreciated. Thanks in advance. [file name=query-37ab101e3a539a71be9c962f72749d92.doc size=49152]http://www.jasperforge.org/components/com_joomlaboard/uploaded/files/query-37ab101e3a539a71be9c962f72749d92.doc[/file] Post edited by: atanupanda, at: 2007/02/06 10:06Post edited by: atanupanda, at: 2007/02/06 10:09 Link to comment Share on other sites More sharing options...
saradhasivaraman Posted November 2, 2012 Share Posted November 2, 2012 no need html tag <br/> plz remove all the <br> and other html tags if exist .. then place ur generated .class file in the loc where the jrxml lies or export the java class as a jar file and include it in the Tools > Option > classpath.. 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