Chart FX can also read information stored in text files or text streams. Both Tab separated values (TSV) and Comma separated values (CSV) are valid and can be accessed by Chart FX by default, but other formats can also be used.
This feature is supported by the TextProvider class and chart's DataSource property, which are both implemented as follows:
TextProvider txtProvider = new TextProvider("TextFile.txt"); chart1.setDataSource(txtProvider);
|
The text file you will generate depends on the actual data you want Chart FX to take. You can generate a text file with just numerical information or with labels that Chart FX will use to assign to legends. In any case, the format of the text file must follow these guidelines:
- There are as many columns as series in the chart.
- There are as many rows as points per series in the chart.
- Columns must be separated by a tab or comma, or any other character specified in the Separators Property.
- Each row ends in a carriage return.
- No empty lines are allowed after the last row of data.
- Series Legends will be taken from Column headings.
- Point legends (X-axis legends) will be taken from Row headings.
For example, creating a text file that Chart FX will use to:

Please note there's a tab character in the first cell to make the "Sales" label appear as a heading for the first column.
Separators
By default, Chart FX for Java's TextProvider understands commas and tabs as separators. However, columns within the text file can be separated with many other characters, as long as they are always the same, configuring the Text Provider is done as follows:
txtProvider.setSeparators("|");
|
Important Note: Dashes ("-") are not a valid separator since they are used to identify negative values.
Date Formats
When date values are included in the text file in another format than "mm/dd/yyyy" (which is the default format for Chart FX for Java TextProvider), the DateFormat property must be used to create a mask that will instruct Chart FX for Java how to understand the values.
txtProvider.setDateFormat( "dd-MMM-yyy");
|
|