|
|
|
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
Charts
Exporting
Images
Exporting
data
TeeChart's
'Tee' template and data export import format
Import
|
All formats may be copied
to either a file or Clipboard or to a Stream.
Image formats
· JPEG:
JPEGFormat Class
· GIF: GIFFormat
Class
· PNG: PNGFormat
Class
· WBMP: WBMPFormat
Class
Data
formats
· Text:
TextFormat Class
· XML: XMLFormat
Class
· HTML:
HTMLFormat Class
· Excel:
ExcelFormat Class
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.
· TEP
(TeeChart): TemplateExport Classs
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.
TEP
(TeeChart) |
SaveChartToFile |
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
$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 following examples
export the data from a Chart Series in Text or XML format. They may be created
and associated with a Chart Series from which they can export data as either
File, Stream or to the Clipboard.
Example
try {
$myChart->getExport()->getData()->getText()->save($tmpName);
}
Example
try {
$myChart->getExport()->getTemplate()->toXML($tmpName);
$showSavedFile(tmpName);
}
Tee files are TeeChart's
own template format for saving Charts and their data and have the .tej
extension in Java IDE's. Modified Chart properties are saved with the template
and reproduced when the template is imported to a new Chart.
Advantages:
· Tep
files are very small in size, in most cases that offers an advantage over pure
graphics formats (Quicker).
· The
destination Chart for the template is 'live', it can be zoomed and scrolled and
have its properties modified.
· Data
may optionally be included with the tee template according to your preference.
Example
try {
$tChart1->getExport()->getTemplate()->toFile("/temp/chart1.tep");
} catch (IOException ex1) {
ex1.printStackTrace();
}
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 Tep
file from a local file source or http data source.
Example
import from file
$tChart1->getImport()->getTemplate()->fromFile("myFile.tep");
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);
}
© 1996-2008
Steema Software SL. All rights reserved.