From: Nathaniel G. A. <nat...@ya...> - 2003-06-18 21:48:51
|
a couple things: 1) you should not call JFrame.pack() 2) you need to call getGraphics() on the JPanel only after it is visible on the screen as Java will not create a graphics item for non visible components that have never been visible. 3) the size of the JFrame includes the borders of the JFrame itself so you need to size it accordingly. try this: public class a extends JPanel { LegendProperties lp = null; ChartProperties cp = null; BarChartProperties ctp = null; AxisChart c = null; AxisProperties ap = null; public a() throws Exception { ChartProperties cp = new ChartProperties(); ctp = new BarChartProperties(); String[] xAxisLabels = {"1995", "1996", "1997", "1998", "1999", "2000", "2001", "2002","2003", "2004"}; String xAxisTitle = "Years"; String yAxisTitle = "Problems"; String title = "Micro$oft At Work"; DataSeries ds = new DataSeries( xAxisLabels, xAxisTitle, yAxisTitle, title ); double[][] data = new double[][]{{1500, 6880, 4510, 2600, -1200, -1580, 7000, 4555, 4000,6120}}; String[] legendLabels = {"Bugs"}; Paint[] paints = new Paint[]{Color.yellow}; ds.addIAxisPlotDataSet(new AxisChartDataSet( data, legendLabels, paints, ChartType.BAR, ctp)); lp = new LegendProperties(); ap = new AxisProperties(false); c = new AxisChart(ds, cp, ap, lp, 400, 400); //c.setGraphics2D((Graphics2D)getGraphics()); } public static void main(String args[]) throws Exception { JFrame f = new JFrame("a"); f.setSize( 500, 500 ); a a = new a(); a.setSize( 400,400); f.getContentPane().add(a); // f.pack(); f.setVisible(true); a.c.setGraphics2D((Graphics2D)a.getGraphics()); a.c.render(); } } --- Mike Eggleston <mi...@mi...> wrote: > Hi Nathaniel! > > On Wed, 18 Jun 2003, Nathaniel G. Auvil wrote: > > > > > hey Mike. > > > > http://jcharts.sourceforge.net/userGuide/exportingImages.html > > > > > > take a look at the user guide for an example of a Swing app. The package namespace has > changed > > from org.jCharts to org.krysalis.jcharts for the 1.0.0 release, but the code is the same. > > > > At a quick glance, it looks like you only need to set the graphics2D from your JPanel (note > the > > 'J' in front of Panel, which is the Swing classes rather than the AWT Panel Object) and simply > > call Render. > > With the changes to JPanel and JFrame it compiles fine, but gets an error > in the org.jCharts.Chart.render method. > > Mike > > public class a extends JPanel { > LegendProperties lp = null; > ChartProperties cp = null; > BarChartProperties ctp = null; > AxisChart c = null; > AxisProperties ap = null; > > public a() throws Exception { > ChartProperties cp = new ChartProperties(); > ctp = new BarChartProperties(); > > String[] xAxisLabels = {"1995", "1996", "1997", "1998", "1999", "2000", "2001", "2002", > "2003", "2004"}; > String xAxisTitle = "Years"; > String yAxisTitle = "Problems"; > String title = "Micro$oft At Work"; > DataSeries ds = new DataSeries( xAxisLabels, xAxisTitle, yAxisTitle, title ); > > double[][] data = new double[][]{{1500, 6880, 4510, 2600, -1200, -1580, 7000, 4555, > 4000, 6120}}; > String[] legendLabels = {"Bugs"}; > Paint[] paints = new Paint[]{Color.yellow}; > ds.addIAxisPlotDataSet(new AxisChartDataSet( data, legendLabels, paints, ChartType.BAR, > ctp)); > > lp = new LegendProperties(); > ap = new AxisProperties(false); > > c = new AxisChart(ds, cp, ap, lp, 400, 400); > c.setGraphics2D((Graphics2D)getGraphics()); > } > > public static void main(String args[]) throws Exception { > JFrame f = new JFrame("a"); > > a a = new a(); > > f.getContentPane().add(a); > f.pack(); > f.setVisible(true); > a.c.render(); > } > } > > :!javac a.java && java a > Exception in thread "main" java.lang.NullPointerException > at org.jCharts.Chart.render(Unknown Source) > at a.main(a.java:46) > > ===== http://nathaniel-auvil.blog-city.com/ __________________________________ Do you Yahoo!? SBC Yahoo! DSL - Now only $29.95 per month! http://sbc.yahoo.com |