JMSL Chart Programmer’s Guide
Using the Scalable Vector Graphics (SVG) API
Scalable Vector Graphics (SVG) is an XML vocabulary for vector graphics.
JMSL's SVG support is based on the Apache Batik toolkit. Batik is not included with JMSL Numerical Library. It can be downloaded, for free, from the Apache Batik site. The batik.jar file needs to be added to the CLASSPATH.
Once batik.jar is installed, a JMSL chart can be saved as an SVG file by using the Chart.writeSVG method.
SVG can also be created from a JFrameChart window. Its File SaveAs menu allows the chart to be saved as either a PNG image or as an SVG file. The SVG option is active only if batik.jar is in the CLASSPATH.
The following example generates SVG output. The output encoding format is set to UTF-8. This is done because SVG renderers do not support all encodings. The UTF-8 is the most general encoding.
View code file
 
import com.imsl.chart.*;
import java.io.*;
import java.awt.*;
 
public class SampleSVG {
public static void main(String argv[]) throws java.io.IOException {
Frame frame = new Frame();
frame.show();
frame.setSize(500, 500);
frame.setVisible(false);
Chart chart = createChart(frame);
OutputStream os = new FileOutputStream("SampleSVG.svg");
Writer writer = new OutputStreamWriter(os, "UTF-8");
chart.writeSVG(writer, true);
System.exit(0);
}
 
static Chart createChart(Component component) {
Chart chart = new Chart(component);
AxisXY axis = new AxisXY(chart);
int npoints = 20;
double dx = .5 * Math.PI/(npoints-1);
double x[] = new double[npoints];
double y[] = new double[npoints];
 
// Generate some data
for (int i = 0; i < npoints; i++){
x[i] = i * dx;
y[i] = Math.sin(x[i]);
}
new Data(axis, x, y);
return chart;
}
}