|
Chart Builder API (beta) | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--oracle.ord.media.chart.io.TimeSeriesFileReader
TimeSeriesFileReader reads time series data from files or streams and converts the data into arrays suitable for populating charts. Flexible, locale-specific formats of dates and numbers are supported -- parsing is performed with the DateFormat and NumberFormat classes. Flexible file formats are supported, including csv (comma-separated values) and tsv (tab-separated values).
For example, files in the following forms can be transformed into arrays suitable for populating Chart Builder: AxisCharts.
DATE OBS1 OBS2 ... OBSN DATE, OBS1, OBS2, ... OBSN
For example, consider a file, "myfile.txt", containing one date column and one observation column:
01/01/2000 22.50 02/01/2000 24.25 03/01/2000 25.00 ...
This file can be transformed into one array of Date and another array of double as follows:
try { TimeSeriesFileReader tsReader = new TimeSeriesFileReader(); tsReader.readFile("myfile.txt"); java.util.Date FileDates[] = tsReader.getDates(); double FileObs[] = tsReader.getObservations(); } catch (ChartException e) { System.out.println(e.getMessage()); }
In the example, readFile("myfile.txt") is called to read the file myfile.txt, converting the contents to arrays of Date and double. Subsequently, the array of Date is retrieved with getDates() and the array of double is retrieved with getObservations().
Note that each date can be associated with more than one observation. For example, consider a file, "myfile2.txt," that contains one date column and two observations column:
01/01/2000 22.50 22.75 02/01/2000 24.25 24.50 03/01/2000 25.00 25.75 ...
Converting this data to arrays is similar to the earlier example:
try { TimeSeriesFileReader tsReader = new TimeSeriesFileReader(); tsReader.readFile("myfile.txt"); java.util.Date FileDates[] = tsReader.getDates(); double FileObs[] = tsReader.getObservations(0); double FileObs2[] = tsReader.getObservations(1); } catch (ChartException e) { System.out.println(e.getMessage()); }
Note that getObservationCount() can be used to determine the number of observation columns in the file.
Note that TimeSeriesFileReader expects that each Date is associated with the same number of observations. Errors will be flagged for files that do not adhere to this association.
Also, note that the file may contain characters that are not Dates or Numbers. Any data that is not a Date or Number will be ignored by the file reader. For example, text headers describing the content of the file will be ignored.
Field Summary | |
static int |
DERIVED
Constant indicating that the dimension is derived by the system. |
Constructor Summary | |
TimeSeriesFileReader()
|
Method Summary | |
java.util.Date[] |
getDates()
Return the Date array. |
int |
getObservationCount()
Return the number of observations. |
double[] |
getObservations()
Return the observations array. |
double[] |
getObservations(int seriesIndex)
Return the observations array designated by seriesIndex. |
void |
read(java.io.InputStream stream)
Read the data stream designated by the InputStream stream, storing the dates and numerical values in arrays. |
void |
readFile(java.lang.String fileName)
Read the file designated by fileName, storing the dates and numerical values in arrays. |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final int DERIVED
Constructor Detail |
public TimeSeriesFileReader()
Method Detail |
public void readFile(java.lang.String fileName) throws ChartException
public void read(java.io.InputStream stream) throws ChartException
public java.util.Date[] getDates()
public double[] getObservations()
public double[] getObservations(int seriesIndex) throws ChartException
seriesIndex
- Index of the returned observations array.public int getObservationCount()
|
Chart Builder API (beta) | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |