From: Nathaniel G. A. <nat...@ya...> - 2003-04-15 18:01:20
|
--- "Nathaniel G. Auvil" <nat...@ya...> wrote: > Date: Tue, 15 Apr 2003 10:59:20 -0700 (PDT) > From: "Nathaniel G. Auvil" <nat...@ya...> > Subject: Re: [jCharts-users] Swing app question > To: fra...@ag... > > > hi. > > Your problem is the Graphics2D Object coming from your JPanel is null. This is because your app > is not visible on the screen so the jvm does not create the underlying graphics components. To > fix this, simply call the 'setVisible( true );' method on your JFrame before you render the > chart. > > > > > --- fra...@ag... wrote: > > Hi, > > > > I have only downloaded jCharts today, so my experience with package is not great. I really > want > > to use the package to embed charting components in Swing applications. Within the distribution > > I found an example of a Swing PieChart. I tried to follow that example to try and reconstruct > > my own Swing bar chart based on the distributions bar chart example. > > > > The code is given below. All seems to work, the frame gets drawn but finally I get an > exception > > when the "axisChart.render()" method is called: > > > > $ source runharness > > /cygdrive/d/mpowerdem/src/wdiscovery > > java.lang.NullPointerException > > at org.jCharts.Chart.render(Unknown Source) > > at com.agilent.wdiscovery.MainFrame.initComponents(MainFrame.java:81) > > at com.agilent.wdiscovery.MainFrame.<init>(MainFrame.java:34) > > at com.agilent.wdiscovery.LaunchWirelessApp.<init>(LaunchWirelessApp.jav > > a:20) > > at com.agilent.wdiscovery.LaunchWirelessApp.main(LaunchWirelessApp.java: > > 49) > > > > I have tried other things in despair but I'm not getting very far. Can anyone help or point > > me to some other Swing based examples? > > > > Thanks, > > > > Francisco > > > > > -------------------------------------------------------------------------------------------------------------------------------------- > > > > package com.agilent.wdiscovery; > > > > import org.jCharts.chartData.ChartDataException; > > import org.jCharts.properties.*; > > import org.jCharts.chartData.*; > > import org.jCharts.axisChart.*; > > import org.jCharts.types.*; > > import org.jCharts.imageMap.*; > > > > import java.awt.*; > > import java.awt.event.*; > > import java.awt.image.*; > > import javax.swing.*; > > > > /** > > * <p>Title: </p> > > * <p>Description: </p> > > * <p>Copyright: Copyright (c) 2003</p> > > * <p>Company: </p> > > * @author unascribed > > * @version 1.0 > > */ > > > > public class MainFrame extends JFrame { > > private JPanel contentPane; > > private BorderLayout borderLayout1 = new BorderLayout(); > > private JPanel jPanel1 = new JPanel(true); > > > > //Construct the frame > > public MainFrame() { > > enableEvents(AWTEvent.WINDOW_EVENT_MASK); > > try { > > jbInit(); > > initComponents(); > > } > > catch(Exception e) { > > e.printStackTrace(); > > } > > } > > //Component initialization > > private void jbInit() throws Exception { > > //setIconImage(Toolkit.getDefaultToolkit().createImage(MainFrame.class.getResource("[Your > > Icon]"))); > > contentPane = (JPanel) this.getContentPane(); > > contentPane.setLayout(borderLayout1); > > this.setSize(new Dimension(400, 300)); > > this.setTitle("802.11 Wireless Discovery"); > > jPanel1.setBorder(BorderFactory.createEtchedBorder()); > > contentPane.add(jPanel1, BorderLayout.CENTER); > > } > > //Overridden so we can exit when window is closed > > protected void processWindowEvent(WindowEvent e) { > > super.processWindowEvent(e); > > if (e.getID() == WindowEvent.WINDOW_CLOSING) { > > System.exit(0); > > } > > } > > > > private void initComponents() throws ChartDataException, PropertyException { > > String[] xAxisLabels= { "1998", "1999", "2000", "2001", "2002", "2003", "2004" }; > > String xAxisTitle= "Years"; > > String yAxisTitle= "Problems"; > > String title= "Micro$oft at Work"; > > DataSeries dataSeries = new DataSeries( xAxisLabels, xAxisTitle, yAxisTitle, title ); > > > > double[][] data= new double[][]{ { 250, 45, -36, 66, 145, 80, 55 } }; > > String[] legendLabels= { "Bugs" }; > > Paint[] paints= new Paint[]{ Color.blue.darker() }; > > BarChartProperties barChartProperties= new BarChartProperties(); > > AxisChartDataSet axisChartDataSet= new AxisChartDataSet( data, legendLabels, paints, > > ChartType.BAR, barChartProperties ); > > dataSeries.addIAxisPlotDataSet( axisChartDataSet ); > > > > ChartProperties chartProperties= new ChartProperties(); > > > > //---to make this plot horizontally, pass true to the AxisProperties Constructor > > //AxisProperties axisProperties= new AxisProperties( true ); > > AxisProperties axisProperties= new AxisProperties(); > > LegendProperties legendProperties= new LegendProperties(); > > AxisChart axisChart= new AxisChart( dataSeries, chartProperties, axisProperties, > > legendProperties, 200, 200 ); > > > > axisChart.setGraphics2D( (Graphics2D) this.jPanel1.getGraphics() ); > > axisChart.render(); > > } > > } > > > > > > ------------------------------------------------------- > > This sf.net email is sponsored by:ThinkGeek > > Welcome to geek heaven. > > http://thinkgeek.com/sf > > _______________________________________________ > > jCharts-users mailing list > > jCh...@li... > > https://lists.sourceforge.net/lists/listinfo/jcharts-users > > > ===== > > > __________________________________________________ > Do you Yahoo!? > The New Yahoo! Search - Faster. Easier. Bingo > http://search.yahoo.com > ===== __________________________________________________ Do you Yahoo!? The New Yahoo! Search - Faster. Easier. Bingo http://search.yahoo.com |