import com.imsl.chart.*; import com.imsl.io.FlatFile; import java.io.*; import java.sql.SQLException; import java.util.StringTokenizer; public class SampleBoxPlot extends JFrameChart { public SampleBoxPlot() throws IOException, java.sql.SQLException { // Read the data InputStream is = SampleBoxPlot.class.getResourceAsStream("FisherIris.csv"); DataReader reader = new DataReader(is); int nColumns = 5; int nObs = 150; String labels[] = new String[nColumns]; for (int i = 0; i < nColumns; i++) { labels[i] = reader.getMetaData().getColumnName(i+1); } double irisData[][] = new double[nColumns][nObs]; for (int j = 0; reader.next(); j++) { for (int i = 0; i < nColumns; i++) { irisData[i][j] = reader.getDouble(i+1); } } // Setup the chart Chart chart = getChart(); AxisXY axis = new AxisXY(chart); BoxPlot boxPlot = new BoxPlot(axis, irisData); boxPlot.setBoxPlotType(BoxPlot.BOXPLOT_TYPE_HORIZONTAL); boxPlot.setLabels(labels); boxPlot.getBodies().setFillColor("green"); boxPlot.setMarkerType(BoxPlot.MARKER_TYPE_FILLED_CIRCLE); boxPlot.getOutsideMarkers().setMarkerColor("blue"); boxPlot.getFarMarkers().setMarkerColor("red"); boxPlot.setNotch(true); } public static void main(String argv[]) throws IOException, java.sql.SQLException { new SampleBoxPlot().setVisible(true); } /** * Read the Fisher Iris data */ static private class DataReader extends FlatFile { public DataReader(InputStream is) throws IOException { super(new BufferedReader(new InputStreamReader(is))); String line = readLine(); StringTokenizer st = new StringTokenizer(line, ","); for (int j = 0; st.hasMoreTokens(); j++) { setColumnName(j+1, st.nextToken().trim()); setColumnClass(j, Double.class); } } } }