/** * Attach a DataSet to the graph. By attaching the data set the class can draw the data through * its paint method. */ public void attachDataSet(DataSet d) { if (d != null) { dataset.addElement(d); d.g2d = this; } }
/** * Load and Attach a DataSet from an array. The method loads the data into a DataSet class and * attaches the class to the graph for plotting. * * <p>The data is assumed to be stored in the form x,y,x,y,x,y.... A local copy of the data is * made. * * @param data The data to be loaded in the form x,y,x,y,... * @param n The number of (x,y) data points. This means that the minimum length of the data array * is 2*n. * @return The DataSet constructed containing the data read. */ public DataSet loadDataSet(double data[], int n) { DataSet d; try { d = new DataSet(data, n); dataset.addElement(d); d.g2d = this; } catch (Exception e) { System.out.println("Failed to load Data set "); e.printStackTrace(); return null; } return d; }