Example: Area Chart

An area chart is constructed in this example. Three data sets are used and a legend is added to the chart. This class can be used either as an applet or as an application.
import com.imsl.chart.*;
import java.awt.Color;

public class AreaEx1 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];
        double y3[] = 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]);
            y3[i] = Math.atan(x[i]);
        }
        Data d1 = new Data(axis, x, y1);
        Data d2 = new Data(axis, x, y2);
        Data d3 = new Data(axis, x, y3);
        
        //	Set Data Type to Fill Area
        axis.setDataType(d1.DATA_TYPE_FILL);
        
        //	Set Line Colors
        d1.setLineColor(Color.red);
        d2.setLineColor(Color.black);
        d3.setLineColor(Color.blue);
        
        //	Set Fill Colors
        d1.setFillColor(Color.red);
        d2.setFillColor(Color.black);
        d3.setFillColor(Color.blue);
        
        //	Set Data Labels
        d1.setTitle("Sine");
        d2.setTitle("Cosine");
        d3.setTitle("ArcTangent");
        
        //	Add a Legend
        Legend legend = chart.getLegend();
        legend.setTitle(new Text("Legend"));
        legend.setPaint(true);
        
        //	Set the Chart Title
        chart.getChartTitle().setTitle("Area Plots");
    }
    
    
    public static void main(String argv[]) {
        JFrameChart frame = new JFrameChart();
        AreaEx1.setup(frame.getChart());
        frame.show();
    }
}

Output

eqn_0348

Link to Java source.