Creating Charts
The Groovy API is plot-centric and provides convenience methods for creating plots
then displaying them simply by calling the createFrame() method.
import kcl.waterloo.plot.WPlot
p=WPlot.scatter(['XData', 1..10, 'YData', 1..10])
p.createFrame();
In this example, the code creates a WPlot instance. The WPlot class is
just a wrapper class to which some convenience methods have been attached.
One of these, createFrame, provides a thread-safe method to create
a chart to house the plot.
Although the Waterloo Groovy API is plot-centric, Groovy is not. That means you can work with Swing, SwingBuilder, JavaFX, GroovyFX etc directly but still use the Waterloo Groovy API to build the plots:
import javax.swing.JFrame
import kcl.waterloo.graphics.*
import kcl.waterloo.plot.WPlot
JFrame f=new JFrame()
GJGraphContainer g=GJGraphContainer.createInstance(GJGraph.createInstance())
f.getContentPane().add(g)
f.setSize(300,300);
f.setVisible(true)
p=WPlot.scatter(['XData', 1..10, 'YData', 1..10])
g.getView().add(p.getPlot())
The code above can be run in an instance of the Groovy Console. Note, however, that:
- This example code is not thread-safe while the earlier code using the WPlot createFrame method was.
- Waterloo needs to be added to the class path as described here