![]() |
Contents page Previous | Next |
This tutorial overviews exporting TeeCharts in various formats and importing TeeChart's own .tee format Chart templates. See the TeeChart example code in the Examples folder below your TeeChart installation folder.
| Contents |
Exporting ChartsExporting ImagesJPEGGIF PNG Exporting dataTeeChart's 'Tee' template and data export import formatTee filesImport |
All formats may be copied to either a file or
Clipboard or to a Stream.
Image formats
Data formats
Other formats
Ten format is a flexible format that stores Chart property information and, optionally, Chart data. Files are small (data dependent) and ideal for network use to update live client based Charts.
Other formats
Tee format is a flexible format that stores Chart property information and, optionally, Chart data. Files are small (data dependent) and ideal for network use to update live client based Charts.
| TEE (TeeChart) | SaveChartToFile |
Chart TeeExport
method.Example
TeeExport(Self,TheChart);
Exporting to a file is reasonable straightforward, in most cases you just need to define the destination filename.
Example
With SaveDialog1 do if Execute then Chart1.SaveToBitmapFile(SaveDialog1.FileName);
JPEG file export has additional parameters for speed and quality. See the JPEG demo included in the Examples folder.
Example
int tmpResult = fc.showSaveDialog(JpegExportDemo.this);
if (tmpResult == JFileChooser.APPROVE_OPTION) {
File file = fc.getSelectedFile();
String tmpName = file.getAbsolutePath();
if (!ExportUtils.isExtension(file, ExportUtils.JPG)) {
tmpName = ExportUtils.replaceExtension(file, ExportUtils.JPG);
}
myChart.getExport().getImage().getJPEG().save(tmpName);
}
Performance, jpegBestQuality, and the Compression Quality percentage (high value less compression), will make the file larger and thus slower to transmit across a network - quality is better though! You will need to decide on the best balance to suit your application.
TeeChart provides the means to create GIF Chart images but you should check your licensing position with Unisys for use of GIF LZW encoded images. The alternative RLE encoding is not subject to Unisys licenses.
Example by code
int tmpResult = fc.showSaveDialog(GifExportDemo.this);
if (tmpResult == JFileChooser.APPROVE_OPTION) {
File file = fc.getSelectedFile();
String tmpName = file.getAbsolutePath();
if (!ExportUtils.isExtension(file, ExportUtils.GIF)) {
tmpName = ExportUtils.replaceExtension(file, ExportUtils.GIF);
}
myChart.getExport().getImage().getGIF().save(tmpName);
}
The PNG format retains many of the advantages of the GIF format but also
provides capabilities beyond those of GIF. PNG improves on GIF in its ability to
progressively display an image; that is, to display better and better
approximations of the image as it arrives over a network connection.
Example
int tmpResult = fc.showSaveDialog(PngExportDemo.this);
if (tmpResult == JFileChooser.APPROVE_OPTION) {
File file = fc.getSelectedFile();
String tmpName = file.getAbsolutePath();
if (!ExportUtils.isExtension(file, ExportUtils.PNG)) {
tmpName = ExportUtils.replaceExtension(file, ExportUtils.PNG);
}
myChart.getExport().getImage().getPNG().save(tmpName);
}
The TeeStore unit includes the definition of the TSeriesData component and its descendants:
| Text | TSeriesDataText |
| XML | TSeriesDataXML |
| HTML | TSeriesDataHTML |
| Excel | TSeriesDataXLS |
The above components may be created and associated with a Chart Series from which they can export data as either File, Stream or to the Clipboard. The following example exports the data from a Chart Series to an HTML table:
With TSeriesDataHTML.Create(Chart1,Series1) do
Begin
IncludeHeader:=True;
SaveToFile('c:\tempdata\Series1HTMLData.txt');
end;
The output of the above with a random dataset is the following:
| Series1 |
| 308 |
| 267 |
| 170 |
| 192 |
| 284 |
| 253 |
| 265 |
| 296 |
| 335 |
| 454 |
Tee files are TeeChart's own template format for saving Charts and their data. Modified Chart properties are saved with the template and reproduced when the template is imported to a new Chart.
Advantages:
The declarations for SaveChartToFile/SaveChartToStream are:
procedure SaveChartToFile(AChart: TCustomChart; Const AName: String; IncludeData: Boolean);
procedure SaveChartToStream(AChart: TCustomChart; AStream: TStream; IncludeData: Boolean);
{See the TeeStore unit for more information}
Example
//Add the unit teestore to the 'Uses' section of your project begin With SaveDialog1 do begin Filter:='Teefiles|*.tee'; if Execute then SaveChartToFile(Chart1,SaveDialog1.FileName,True); end
Example which shows how to export and load from/to xml :
Save to xml;
try {
myChart.getExport().getTemplate().toXML(tmpName);
showSavedFile(tmpName);
} catch (FileNotFoundException e) {
System.out.println(e);
}
Load from xml:
try { myChart.setChart(myChart.getImport().getTemplate().fromXML(tmpName));
myChart.repaint();
}
catch (FileNotFoundException e) {
System.out.println(e);
}
Import a saved Tee file from a local file source or http data source.
Example which shows how to export and load from/to xml :
Save to xml;
try {
myChart.getExport().getTemplate().toXML(tmpName);
showSavedFile(tmpName);
} catch (FileNotFoundException e) {
System.out.println(e);
}
Load from xml:
try { myChart.setChart(myChart.getImport().getTemplate().fromXML(tmpName));
myChart.repaint();
}
catch (FileNotFoundException e) {
System.out.println(e);
}
Example
import from file
tChart1.getImport().getTemplate().fromFile("myFile.tej");
or
XML..
tChart1.getImport().getTemplate().fromXML("myFile.xml");
or
Stream..
try {
//( 1) Save the template into a Stream...
ByteArrayOutputStream m = new ByteArrayOutputStream();
myChart.getExport().getTemplate().toStream(m);
//( 2) Load the template into other Chart...
copyChart.setChart(copyChart.getImport().getTemplate().fromStream(
new ByteArrayInputStream(m.toByteArray())
));
//( 3) repaint the Chart
copyChart.repaint();
} catch (IOException ex) {
System.out.println(ex);
} catch (ClassNotFoundException ex) {
System.out.println(ex);
}
You may also import a TeeChart file from URL, LoadChartFromURL.
![]() |
![]() |