Example: Picture Chart

A picture plot is constructed in this example. This class can be used either as an applet or as an application.
import com.imsl.chart.*;
import java.awt.Color;
import java.net.URL;
import javax.swing.ImageIcon;


public class PictureEx1 extends javax.swing.JApplet {
    private JPanelChart panel;
    
    public void init() {
        Chart chart = new Chart(this);
        panel = new JPanelChart(chart);
        getContentPane().add(panel, java.awt.BorderLayout.CENTER);
        setup(chart);
    }
    
    static private void setup(Chart chart) {
        AxisXY axis = new AxisXY(chart);
        
        int	npoints = 20;
        double dx = .5 * Math.PI/(npoints - 1);
        double x[] = new double[npoints];
        double y1[] = new double[npoints];
        double y2[] = new double[npoints];
        
        //	Generate some data
        for (int i = 0; i < npoints; i++){
            x[i] = i * dx;
            y1[i] = Math.sin(x[i]);
            y2[i] = Math.cos(x[i]);
        }
        Data d1 = new Data(axis, x, y1);
        Data d2 = new Data(axis, x, y2);
        
        //	Load Images
        d1.setDataType(Data.DATA_TYPE_PICTURE);
        d1.setImage(loadImage("marker.gif"));
        d2.setDataType(Data.DATA_TYPE_PICTURE);
        d2.setImage(loadImage("marker2.gif"));
        
        //	Set the Chart Title
        chart.getChartTitle().setTitle("Picture Plot");
    }
    
    static private java.awt.Image loadImage(String name) {
        return new ImageIcon(PictureEx1.class.getResource(name)).getImage();
    }

    
    public static void main(String argv[]) {
        JFrameChart frame = new JFrameChart();
        PictureEx1.setup(frame.getChart());
        frame.show();
    }
}

Output

eqn_0131

Link to Java source.