Adding a Chart to an Application

For simplicity, most of the examples in this manual use the JFrameChart class.   JFrameChart is useful for quickly building an application that is a chart. The class JPanelChart is used to build a chart into a larger application. It extends  Swing's JPanel class and can be used wherever a JPanel can be used. The following code shows a JPanelChart being created, added to a JFrame, and having a chart tree added to the JPanelChart.   The generated chart is the same as the first one on this page and so is not shown here.

 

(Download Code)

 

import com.imsl.chart.*;

 

public class SampleJPanel extends javax.swing.JFrame {

    private JPanelChart jPanelChart;

 

    public SampleJPanel() {

        this.setSize(500, 500);

        jPanelChart = new JPanelChart();

        getContentPane().add(jPanelChart);

       

        Chart chart = jPanelChart.getChart();

        AxisXY axis = new AxisXY(chart);

        double y[] = {4, 2, 3, 9};

        new Data(axis, y);

    }

   

    public static void main(String argv[]) {

        new SampleJPanel().setVisible(true);

    }

}

 



Visual Numerics - Developers of IMSL and PV-WAVE
http://www.vni.com/
PHONE: 713.784.3131
FAX:713.781.9260