Jump to content
Changes to the Jaspersoft community edition download ×

has Anybody created a chart & has it worked?


2005 IR Help

Recommended Posts

By: djiska - djiska

has Anybody created a chart & has it worked?

2005-08-02 10:52

Hi

 

I take a long time trying that it works a charts in a application. I'm bored. The chart works in IReports but when I pass it a application, it doesn't work. it shows me the error:

 

There is exception herenet.sf.jasperreports.engine.JRException: Error loading scriptlet class : Diagrama_Barra_JunScriptlet

 

I don?t know if I have got to create the chart in the Scriptlet if I don't have to create it. Also I`ve seen some examples like

 

// Second, create a map of parameters to pass to the report.

Map parameters = new HashMap();

parameters.put("employeeChart", createEmployeeChartImage());

 

But this I don't understand why is there a parameter "employeeChart" and is the value created to a function? which I don't know where it is . My answer, this function there is to create it in the scriptle. has The name to be the same to the chart.

 

If there is a person who describes me the step to step, how i have got to create it to work in a application. I'd be thankfull.

 

Thank you very much.

 

 

 

 

 

 

By: armov - armov

RE: has Anybody created a chart & has it worked?

2005-08-02 14:08

I recently created a pie chart with the jfreechart library, I'm developing a web based application and it works perfectly. Here's the code of my scriptlet:

 

package soga;

 

import net.sf.jasperreports.engine.JRDefaultScriptlet;

import net.sf.jasperreports.engine.JRScriptletException;

import org.jfree.chart.ChartFactory;

import org.jfree.chart.JFreeChart;

import org.jfree.chart.plot.PiePlot3D;

import org.jfree.data.general.DefaultPieDataset;

import org.jfree.util.Rotation;

import java.sql.*;

 

 

public class JFreeChartScriptlet extends JRDefaultScriptlet{

public void afterReportInit() throws JRScriptletException{

Statement st;

ResultSet rs;

try{

DefaultPieDataset dataset = new DefaultPieDataset();

String fini = String.valueOf(this.getParameterValue("fini"));

String ffin = String.valueOf(this.getParameterValue("ffin"));

st = Conector.con.createStatement();

rs = st.executeQuery("SELECT CODCAUSAL,NOMBRE FROM CAUSALNP");

while(rs.next()){

String nombrecausal = rs.getString(2);

double porcentajecausal = getCausalPercent(rs.getInt(1),fini,ffin);

dataset.setValue(nombrecausal,new Double(porcentajecausal));

}

rs.close();

st.close();

JFreeChart chart = ChartFactory.createPieChart3D("INFORME - CAUSALES DE NO PAGO",dataset,true,true,false);

PiePlot3D plot = (PiePlot3D) chart.getPlot();

plot.setStartAngle(290);

plot.setDirection(Rotation.CLOCKWISE);

plot.setForegroundAlpha(0.5f);

plot.setNoDataMessage("No data to display");

this.setVariableValue("Chart", new JCommonDrawableRenderer(chart));

}

catch(Exception ex){

ex.printStackTrace();

}

}

public int getTotalCausal(int cod, String fini, String ffin){

int sum=0;

Statement st;

ResultSet rs;

try{

st = Conector.con.createStatement();

rs = st.executeQuery("SELECT COUNT(CAUSALNP_CODCAUSAL) FROM GESTION WHERE CAUSALNP_CODCAUSAL="+cod+" AND FGESTION>='"+fini+"' AND FGESTION<='"+ffin+"'");

while(rs.next()){

sum = rs.getInt(1);

}

rs.close();

st.close();

}

catch(Exception ex){

ex.printStackTrace();

}

return sum;

}

public double getCausalPercent(int cod, String fini, String ffin){

double percent = 0;

int sum = 0;

Statement st;

ResultSet rs;

try{

st = Conector.con.createStatement();

rs = st.executeQuery("SELECT COUNT(CAUSALNP_CODCAUSAL) FROM GESTION WHERE FGESTION>='"+fini+"' AND FGESTION<='"+ffin+"'");

while(rs.next()){

sum = rs.getInt(1);

}

rs.close();

st.close();

if(sum==0){

percent=0;

}

else{

percent = (getTotalCausal(cod,fini,ffin)*100)/sum;

}

}

catch(Exception ex){

ex.printStackTrace();

}

return percent;

}

}

 

If you have any comments publish your mail, I'll sent you all the needed files. Remember that there is an abstract class "JCommonDrawableRenderer" that you have to copy to your project folder, otherwise when you define the chart, it won't work.

See ya...

 

 

 

 

By: djiska - djiska

RE: has Anybody created a chart & has it worked?

2005-08-03 12:45

Hi

 

Thank you very much. I'm going to look at it and understand it. if i have got a doubt I tell you it. Maybe you have saved me the life.

 

See you and greets

 

 

 

 

By: djiska - djiska

RE: has Anybody created a chart & has it worked?

2005-08-03 15:35

Hi armov

 

I have tried it and it gives me the same error:

 

There is exception herenet.sf.jasperreports.engine.JRException: Error loading scriptlet class : Diagrama_Barra_JunScriptlet

 

I have seen a thread in jasper forum where they tells i have got to put the file class in directory where i have got the class files. I have put it also there. And it happens the same.

 

ahh!! I think the class JCommonDrawableRenderer has not got the version jfreechart-0.9.21. I' m looking for I don't find it. I think the vesion jfreechart-1.0.0-rc1 has got.

 

I don't know I'm doing bad.

 

Anyone idea?

 

 

 

 

By: armov - armov

RE: has Anybody created a chart & has it worked?

2005-08-04 00:18

Ok, that kind of exception never appeared to me... it's weird.

What you saw at that threat is true, you HAVE to put your scriptlet and all the files that the scriptlet uses like connections, objects, everything.... just put it all together in the same folder. If you're using packages, in the project properties, be sure to write something like this: [package.class] where package is the folder where the scriptlet is and the class the scriptlet.

try also copying all the .jar files inside the iReport lib to your JRE path (C:Program FilesJavajre1.5.0_04libext) and don't forget to reboot. The JCommonDrawableRenderer its a class that you have to define by yourself here's the code that I'm using for my scriptlet, I took it from the jfreechart example:

 

package soga;

 

import java.awt.Graphics2D;

import java.awt.geom.Rectangle2D;

import net.sf.jasperreports.engine.JRAbstractSvgRenderer;

import org.jfree.ui.Drawable;

 

public class JCommonDrawableRenderer extends JRAbstractSvgRenderer{

private Drawable drawable = null;

public JCommonDrawableRenderer(Drawable drawable)

{

this.drawable = drawable;

}

public void render(Graphics2D grx, Rectangle2D rectangle)

{

if (drawable != null)

{

drawable.draw(grx, rectangle);

}

}

}

 

This file uses the jcommon library I think, don't forget to import it.

 

See ya...

 

 

 

 

By: djiska - djiska

RE: has Anybody created a chart & has it worked?

2005-08-04 10:53

Hi armov

 

I'm going to try it if it works. I'll tell you how it is the thing.

 

see you

 

 

 

 

By: djiska - djiska

RE: has Anybody created a chart & has it worked?

2005-08-04 14:04

Hi

 

I think the trouble is in the application, it doesn't find the Diagrama_Barra_JunScriptlet.class file with the right package . Maybe, because when I compile it in ireports. I don`t put the package. I write the package when I obtain the java file. Then I write package pfc. I`ve tried to write it in scriptlet Editor but when I compile it gives me a error. For that reason I do so. Perhaps that is that cause. But I don't know another way how i do it.

 

 

greets

 

 

 

 

 

By: djiska - djiska

RE: has Anybody created a chart & has it worked?

2005-08-08 12:47

Hi armov

 

I already have gotten it!!!, the trouble is the package. It doesn't take well when I put the package's name and I don't know why. But so It works.

 

Thank you for you help.

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Popular Days

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