Import and Export Methods
Chart FX provides two important methods (Import and Export) that enable you (or your end users) to save chart files, images and data in a variety of formats.
There are also other file types in Chart FX called "Chart Templates" that allow you to save the appearance (Colors, Chart Types and Styles, Visible Tools, etc.) of the chart in a file so you can later apply it to another chart. This allows you to reuse code instead of setting the same attributes for all of your individual charts.
Note: Templates save all the information that is not data related. This means, it will not save the values, number of series or points, or any other property related to this data, such as MultiType settings and Min, Max values in the chart axes.
File Formats
The following file formats are supported by the Import and Export methods:
- BINARY: Exports and imports chart settings to a binary file.
- BINARY_TEMPLATE: Exports chart settings to a binary file with 'Template' pre-assigned, using the FileMask property.
- XML: Exports chart settings to an XML file.
- TEXT: Exports chart data to a Text File.
- JPEG: Exports the charts as a JPEG image.
- PNG: Exports the chart as a PNG image.
The Export Method
This method is used to export the chart data and/or set properties to the clipboard, file or stream in different formats.
Exporting to a File
chart1.exportChart(FileFormat, FileName);
|
Where FileFormat can be any of the supported file formats, and FileName is the file name (including the path). Example:
chart1.exportChart(FileFormat.BINARY, application.getRealPath("/test") + "/chart.bin");
|
Exporting to a Stream
chart1.exportChart(FileFormat, StreamName);
|
Where FileFormat can be any of the supported file formats, and StreamName is the name of a previously opened StTextream. Exporting the chart to an open stream is useful when you need to save the chart inside one of your proprietary files; in other words, it allows you to save the chart and any other data into the same file. Also, streams are particularly useful if you want to save the chart in a database.
The FileMask Property
Whether you are saving chart files in Binary or XML format, you can control what is saved in the file by manipulating the FileMask property. The Binary format will save visual attributes and data; XML will save only visual attributes.
This is a mask property that allows you to specify which visual attributes you want the chart file to save when you invoke the exportChart method. By default, this property is set to save all visual attributes including the data.
However, if you want to save everything but the titles in the chart, you will set this property before invoking the exportChart method as follows:
chart1.setFileMask(chart1.getFileMask() | FileMask.ALL ^ FileMask.TITLES);
|
This property is particularly useful because it allows you to customize how chart files are saved, this way you can build your own chart templates.
This property is a mask property, which means all settings represent a bit in the word that you need to turn on or off according to what you want. For this purpose you’ll use the bitwise operators provided by your development platform.
Because it is a mask property, you must make sure you use these operators to turn on/off bits and avoid losing previous settings to the property. For example, if you want to turn on the TOOLS setting, the right way of setting this property is:
chart1.setFileMask(chart1.getFileMask() | FileMask.TOOLS);
|
Additionally, the BinaryTemplate format will save a Binary format with only a set of pre-defined visual attributes.
The Import Method
The Import method is used to import a chart previously saved with the Export method. The Import method works exactly like the Export method and uses the same syntax and parameters. Below is a sample:
chart1.importChart(FileFormat.BINARY_TEMPLATE, application.getRealPath("/test") + "/chart.cfx"));
|
|