My Java Agent is on Domino R8.5.2 at Iseries V6R1 , import jcommon-1.0.16.jar and jfreechart-1.0.13.jar.
I could run JfreeChart Java Agent on Notes Client or Domino Designer, it will show me Pie Chart or Bar chart and ChartUtilities.saveChartAsJPEG to local drive c:. Please Refer Code 1.
I got some problems
- Can not run this java agent on web, it will show me in the Log
2012/04/02 02:45:07 PM HTTP JVM: Exception in thread “Launcher: JavaAgent”
2012/04/02 02:45:07 PM HTTP JVM: java.lang.NoClassDefFoundError: org.jfree.data.general.PieDataset
2012/04/02 02:45:07 PM HTTP JVM: at java.lang.J9VMInternals.verifyImpl(Native Method)
2012/04/02 02:45:07 PM HTTP JVM: at java.lang.J9VMInternals.verify(J9VMInternals.java:72)
2012/04/02 02:45:07 PM HTTP JVM: at java.lang.J9VMInternals.initialize(J9VMInternals.java:134)
2012/04/02 02:45:07 PM HTTP JVM: at java.lang.J9VMInternals.newInstanceImpl(Native Method)
2012/04/02 02:45:07 PM HTTP JVM: at java.lang.Class.newInstance(Class.java:1325)
2012/04/02 02:45:07 PM HTTP JVM: at lotus.domino.AgentInfo.newInstance(Unknown Source)
2012/04/02 02:45:07 PM HTTP JVM: at lotus.domino.AgentLauncher.run(Unknown Source)
2012/04/02 02:45:07 PM HTTP JVM: at lotus.domino.NotesThread.run(Unknown Source)
2012/04/02 02:45:07 PM HTTP JVM: Caused by:
2012/04/02 02:45:07 PM HTTP JVM: java.lang.ClassNotFoundException: org.jfree.data.general.PieDataset
2012/04/02 02:45:07 PM HTTP JVM: at lotus.domino.AgentLoader.loadClass(Unknown Source)
2012/04/02 02:45:07 PM HTTP JVM: at java.lang.ClassLoader.loadClass(ClassLoader.java:619)
- If I replaced (“c:/JFreeBarChart.jpg”) to (“/WMtemp/JFreeBarChart.jpg”), then I run this code with Domino Designer. It can not save Chart to Iseries(AS400 V6R1), it will catch exception “Problem occurred creating chart “ to Java Console.
Have Anyone idea to fix it ?
Thanks in advance.
Michael
Code 1:
import lotus.domino.*;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartFrame;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.ChartUtilities;
import org.jfree.data.general.DefaultPieDataset;
import org.jfree.ui.RefineryUtilities;
import java.io.File;
import org.jfree.chart.plot.*;
import java.awt.image.BufferedImage;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class JavaAgent extends AgentBase {
public void NotesMain() {
try {
System.out.println("Start Java Chart");
Session session = getSession();
AgentContext agentContext = session.getAgentContext();
// (Your code goes here)
DefaultPieDataset data = new DefaultPieDataset();
data.setValue("Cat 1", 10);
data.setValue("Cat 2", 20);
data.setValue("Cat 3", 30);
data.setValue("Cat 4", 40);
// create a chart...
JFreeChart chart = ChartFactory.createPieChart3D(
"Sample Pie Chart",
data,
true, // Legend
true, // Tooltips
true // URLs
);
PiePlot3D plot = (PiePlot3D) chart.getPlot();
plot.setLabelGenerator(new CustomPieSectionLabelGenerator());
ChartFrame frame = new ChartFrame("First Chart Title", chart);
frame.pack();
RefineryUtilities.centerFrameOnScreen(frame); //center
frame.setVisible(true);
BufferedImage image = chart.createBufferedImage(500,300);
JPanel panel = new JPanel();
panel.add(new JLabel(new ImageIcon(image)));
try {
System.out.println("Write to JPG File");
File file = new File("c:/JFreeBarChart.jpg");
ChartUtilities.saveChartAsJPEG(file, chart, 500, 300);
} catch (Exception e) {
System.err.println("Problem occurred creating chart.");
}
System.out.println("End Java Chart");
} catch(Exception e) {
e.printStackTrace();
}
}
}