Index page

Stock Example
Minimal Example
Line Element Example
Scrolling Example
Normalize Example
Compounding Example
Dynamic Data Example
     Example index : Minimal Example

Minimal Example
Graphs a sine wave in 27 lines of code.

This is a "minimal" demonstration of the webgraph libraries.

back to index

The source code:

/**
 * @version $Id: MinimalExample.java,v 1.2 2000/11/13 18:47:17 Administrator Exp $
 */

import java.applet.*;
import java.awt.*;

import com.smartmoney.webgraph.*;

public class MinimalExample
        extends Applet
{
    static final int ARRAY_SIZE = 300;

    public void init()
    {
        double[] xValues = new double[ARRAY_SIZE];
        double[] yValues = new double[ARRAY_SIZE];
        for (int i = 0; i < ARRAY_SIZE; i++)
        {
            xValues[i] = i;
            yValues[i] = Math.sin(2 * Math.PI * i / ARRAY_SIZE);
        }
        Graph graph = new NumericGraph();
        DataSource dataSource = new SimpleDataSource(xValues, yValues);
        GraphModel model = new GraphModel(dataSource);
        GraphElement line = new LineElement(model);
        graph.setMessage("Minimal Example");
        graph.addGraphElement(line);
        setLayout(new BorderLayout());
        add(graph, BorderLayout.CENTER);
    }
}



Copyright (c) 2006 SmartMoney.com