I have successfully created a dialog screen with four different sample graph types: XY Plot Series, Pie Chart, 3D Horizontal Bar, and an XY area plot. These are samples for now and will eventually be filled with actual data. This all works fantastically ... really cool in fact ... but only while inside of JBuilder V3.5 (yes I know it is a litle out of date). Once I create a JAR file and try to run my application outside of JBuilder I get the following error:
Exception occurred during event dispatching:
java.lang.ExceptionInInitializerError: java.lang.NullPointerException
at javax.swing.ImageIcon.<init>(Unknown Source)
at com.jrefinery.chart.JFreeChartInfo.<init>(Unknown Source)
at com.jrefinery.chart.JFreeChart.<clinit>(Unknown Source)
at com.jrefinery.chart.ChartFactory.createPieChart(Unknown Source)
at collaborate.GraphDlg.jbInit(GraphDlg.java:161)
at collaborate.GraphDlg.<init>(GraphDlg.java:49)
at collaborate.MainFrame.jbGraphs_mouseClicked(MainFrame.java:735)
.......
As far as I can tell I am including all of the com.jrefinery.* stuff in my imports as well as in the jar file. I even added the jfreechart,jcommon,and junit jars to the classpath with the same result.
I am using Java JDK1.3.1_03, jfreechart-0.9.2, jcommon-0.6.4. The Java code is included below. Would switching to the latest versions of jfreechart and jcommon correct the problem. I will be requesting the electronic doc later tonight. I hope I can get this to work because the package is very nice.
------------------------------------------------------------
package collaborate;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.text.*;
import java.util.*;
import javax.swing.*;
import javax.swing.ImageIcon;
import javax.swing.event.*;
import javax.swing.table.*;
import javax.swing.border.*;
import com.jrefinery.data.XYSeries;
import com.jrefinery.data.XYSeriesCollection;
import com.jrefinery.data.CategoryDataset;
import com.jrefinery.data.DefaultPieDataset;
import com.jrefinery.chart.tooltips.StandardXYToolTipGenerator;
import com.jrefinery.data.*;
import com.jrefinery.data.XYDataset;
import com.jrefinery.data.resources.DataPackageResources;
import javax.swing.border.*;
import com.jrefinery.chart.*;
public class GraphDlg extends JDialog {
BorderLayout borderLayout1 = new BorderLayout();
JPanel contentPane;
JPanel jPanel1 = new JPanel();
GridLayout gridLayout1 = new GridLayout();
Border border1;
JButton jButton4 = new JButton();
Frame parent = new Frame();
public GraphDlg(Frame frame, String title, boolean modal) {
super(frame, title, modal);
try {
parent = frame;
jbInit();
pack();
}
catch(Exception ex) {
ex.printStackTrace();
}
}
public GraphDlg() {
this(null, "", false);
}
void jbInit() throws Exception {
contentPane = (JPanel) this.getContentPane();
border1 = new EtchedBorder(EtchedBorder.RAISED,Color.white,new Color(142, 142, 142));
contentPane.setLayout(null);
this.setSize(new Dimension(800, 600));
jPanel1.setMaximumSize(new Dimension(800, 600));
jPanel1.setMinimumSize(new Dimension(800, 600));
jPanel1.setBounds(new Rectangle(15, 25, 775, 515));
jPanel1.setLayout(gridLayout1);
gridLayout1.setRows(2);
gridLayout1.setColumns(2);
contentPane.setMaximumSize(new Dimension(800, 600));
contentPane.setMinimumSize(new Dimension(800, 600));
contentPane.setPreferredSize(new Dimension(800, 600));
contentPane.setBounds(new Rectangle(10, 10, 790, 590));
contentPane.setLayout(null);
jButton4.setFont(new java.awt.Font("Dialog", 1, 16));
jButton4.setMaximumSize(new Dimension(100, 25));
jButton4.setMinimumSize(new Dimension(100, 25));
jButton4.setPreferredSize(new Dimension(100, 25));
jButton4.setMargin(new Insets(2, 2, 2, 2));
jButton4.setText("EXIT");
jButton4.setBounds(new Rectangle(350, 550, 100, 25));
jButton4.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(MouseEvent e) {
jButton4_mouseClicked(e);
}
});
// create a dataset...
DefaultPieDataset data = new DefaultPieDataset();
data.setValue("Category 1", new Double(43.2));
data.setValue("Category 2", new Double(27.9));
data.setValue("Category 3", new Double(79.5));
// create some data...
XYSeries series1 = new XYSeries("Advisory Range");
series1.add(new Integer(1200), new Integer(1));
series1.add(new Integer(1500), new Integer(2));
series1.add(new Integer(1900), new Integer(1));
series1.add(new Integer(2100), new Integer(3));
series1.add(new Integer(2300), new Integer(4));
XYSeries series2 = new XYSeries("Normal Range");
series2.add(new Integer(1400), new Integer(2));
series2.add(new Integer(1700), new Integer(1));
series2.add(new Integer(2000), new Integer(4));
series2.add(new Integer(2300), new Integer(4));
XYSeries series3 = new XYSeries("Recommended");
series3.add(new Integer(2100), new Integer(2));
XYSeries series4 = new XYSeries("Current");
series4.add(new Integer(2400), new Integer(3));
XYSeriesCollection xydata = new XYSeriesCollection();
xydata.addSeries(series1);
xydata.addSeries(series2);
xydata.addSeries(series3);
xydata.addSeries(series4);
// Data for 3D horizontal dataset chart
Number[][] data3D = new Integer[][]
{ { new Integer(10), new Integer(4), new Integer(15), new Integer(14) },
{ new Integer(-5), new Integer(-7), new Integer(14), new Integer(-3) },
{ new Integer(6), new Integer(17), new Integer(-12), new Integer(7) },
{ new Integer(7), new Integer(15), new Integer(11), new Integer(0) },
{ new Integer(-8), new Integer(-6), new Integer(10), new Integer(-9) },
{ new Integer(9), new Integer(8), null, new Integer(6) },
{ new Integer(-10), new Integer(9), new Integer(7), new Integer(7) },
{ new Integer(11), new Integer(13), new Integer(9), new Integer(9) },
{ new Integer(-3), new Integer(7), new Integer(11), new Integer(-10) } };
CategoryDataset dataSet3D = new DefaultCategoryDataset( data3D );
// Data for XY series chart
XYSeries seriesA = new XYSeries("Random A");
seriesA.add(new Integer(1), new Double(500.2));
seriesA.add(new Integer(2), new Double(694.1));
seriesA.add(new Integer(3), new Double(-734.4));
seriesA.add(new Integer(4), new Double(453.2));
seriesA.add(new Integer(5), new Double(500.2));
seriesA.add(new Integer(6), new Double(300.7));
seriesA.add(new Integer(7), new Double(734.4));
seriesA.add(new Integer(8), new Double(453.2));
XYSeries seriesB = new XYSeries("Random B");
seriesB.add(new Integer(1), new Double(700.2));
seriesB.add(new Integer(2), new Double(534.1));
seriesB.add(new Integer(3), new Double(323.4));
seriesB.add(new Integer(4), new Double(125.2));
seriesB.add(new Integer(5), new Double(653.2));
seriesB.add(new Integer(6), new Double(432.7));
seriesB.add(new Integer(7), new Double(564.4));
seriesB.add(new Integer(8), new Double(322.2));
XYSeriesCollection xySeriesData = new XYSeriesCollection(seriesA);
xySeriesData.addSeries(seriesB);
// create a chart...
JFreeChart chart1 = ChartFactory.createPieChart("Sample Pie Chart", data, true);
JFreeChart chart2 = ChartFactory.createXYChart("My Chart", "Calories", "Y", xydata, true);
JFreeChart chart3 = ChartFactory.createHorizontalBarChart3D(
"Horizontal Bar 3D Demo", // chart title
"Category", // domain axis label
"Value", // range axis label
dataSet3D, // data
true // include legend
);
JFreeChart chart4 = ChartFactory.createAreaXYChart("Area Chart Demo",
"Time", "Value",
xySeriesData, true);
XYPlot xyPlot = chart4.getXYPlot();
xyPlot.setForegroundAlpha(0.5f);
XYItemRenderer xyRenderer = xyPlot.getItemRenderer();
xyRenderer.setToolTipGenerator(new StandardXYToolTipGenerator());
XYItemRenderer renderer = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES_AND_LINES, null);
XYPlot plot = (XYPlot)chart2.getPlot();
plot.setXYItemRenderer(renderer);
ValueAxis axis = plot.getRangeAxis();
axis.setTickLabelsVisible(false);
axis.setRange(0.0, 5.0);
ChartPanel cPanel1 = new ChartPanel(chart1, 400, 300, 200, 100, 400, 200,
true, false, false, false, true, true);
ChartPanel cPanel2 = new ChartPanel(chart2, 400, 300, 200, 100, 400, 200,
true, false, false, false, true, true);
ChartPanel cPanel3 = new ChartPanel(chart3, 400, 300, 200, 100, 400, 200,
true, false, false, false, true, true);
ChartPanel cPanel4 = new ChartPanel(chart4, 400, 300, 200, 100, 400, 200,
true, false, false, false, true, true);
cPanel1.setBorder(border1);
cPanel2.setBorder(border1);
cPanel3.setBorder(border1);
cPanel4.setBorder(border1);
// cPanel2.setBorder(BorderFactory.createEtchedBorder());
// cPanel3.setBorder(BorderFactory.createEtchedBorder());
// cPanel4.setBorder(BorderFactory.createEtchedBorder());
jPanel1.add(cPanel1);
jPanel1.add(cPanel2);
jPanel1.add(cPanel3);
jPanel1.add(cPanel4);
contentPane.add(jButton4, null);
contentPane.add(jPanel1, null);
// Set the position in reference to the main window
Dimension dlgSize = this.getPreferredSize();
Dimension frmSize = parent.getSize();
Point loc = parent.getLocation();
this.setLocation((frmSize.width - dlgSize.width) / 2 + loc.x, (frmSize.height - dlgSize.height) / 2 + loc.y);
}
void jButton4_mouseClicked(MouseEvent e) {
this.dispose();
}
void jbExit_actionPerformed(ActionEvent e) {
this.dispose();
}
}
Jar file problem
Re: Jar file problem
Hi Steve,
Just a suggestion: Try to download and use JFreechart 0.9.3 and JCommon 0.7.0. I think it will fix the problem.
Navin Pathuru
Just a suggestion: Try to download and use JFreechart 0.9.3 and JCommon 0.7.0. I think it will fix the problem.
Navin Pathuru
Re: Jar file problem
Thanks for the suggestion Navin - unfortunately it did not help - just a different error:
Exception occurred during event dispatching:
java.lang.ExceptionInInitializerError: java.util.MissingResourceException: Can't
find bundle for base name com.jrefinery.resources.JCommonResources, locale en_U
S
at java.util.ResourceBundle.throwMissingResourceException(Unknown Source
)
at java.util.ResourceBundle.getBundleImpl(Unknown Source)
at java.util.ResourceBundle.getBundle(Unknown Source)
at com.jrefinery.JCommonInfo.<init>(Unknown Source)
at com.jrefinery.JCommon.<clinit>(Unknown Source)
at com.jrefinery.chart.JFreeChartInfo.<init>(Unknown Source)
at com.jrefinery.chart.JFreeChart.<clinit>(Unknown Source)
at com.jrefinery.chart.ChartFactory.createPieChart(Unknown Source)
at collaborate.GraphDlg.jbInit(GraphDlg.java:161)
at collaborate.GraphDlg.<init>(GraphDlg.java:49)
at collaborate.MainFrame.jbGraphs_mouseClicked(MainFrame.java:735)
THe new version of jfreechart made JBuilder complain about two deprecated methods that were being called - those were fixed - still no luck. I have ordered the doc (PDF format) - hopefully I can find the answer there ... unless anyone has any additional suggestions.
Steve Grusak
Exception occurred during event dispatching:
java.lang.ExceptionInInitializerError: java.util.MissingResourceException: Can't
find bundle for base name com.jrefinery.resources.JCommonResources, locale en_U
S
at java.util.ResourceBundle.throwMissingResourceException(Unknown Source
)
at java.util.ResourceBundle.getBundleImpl(Unknown Source)
at java.util.ResourceBundle.getBundle(Unknown Source)
at com.jrefinery.JCommonInfo.<init>(Unknown Source)
at com.jrefinery.JCommon.<clinit>(Unknown Source)
at com.jrefinery.chart.JFreeChartInfo.<init>(Unknown Source)
at com.jrefinery.chart.JFreeChart.<clinit>(Unknown Source)
at com.jrefinery.chart.ChartFactory.createPieChart(Unknown Source)
at collaborate.GraphDlg.jbInit(GraphDlg.java:161)
at collaborate.GraphDlg.<init>(GraphDlg.java:49)
at collaborate.MainFrame.jbGraphs_mouseClicked(MainFrame.java:735)
THe new version of jfreechart made JBuilder complain about two deprecated methods that were being called - those were fixed - still no luck. I have ordered the doc (PDF format) - hopefully I can find the answer there ... unless anyone has any additional suggestions.
Steve Grusak
Re: Jar file problem
Problem fixed! I had to include the JCommonResources class to my build list. Not sure why since it is already in the JAR file. I went to the JCommon forum to find the answer which refered me to:
http://www.object-refinery.com/phorum-3 ... 889&t=3889
Thanks! The whole package is really nice.
Steve Grusak
http://www.object-refinery.com/phorum-3 ... 889&t=3889
Thanks! The whole package is really nice.
Steve Grusak
Re: Jar file problem
Hi Steve,
Glad you got it resolved...thanks for posting the solution as well, it helps for anyone else who goes down the same road as yourself.
Regards,
DG.
Glad you got it resolved...thanks for posting the solution as well, it helps for anyone else who goes down the same road as yourself.
Regards,
DG.