![]() |
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 ImagesJPEGBMP 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 |
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.
Example by code
int tmpResult = fc.showSaveDialog(BmpExportDemo.this); if (tmpResult == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); String tmpName = file.getAbsolutePath(); if (!ExportUtils.isExtension(file, ExportUtils.BMP)) { tmpName = ExportUtils.replaceExtension(file, ExportUtils.BMP); } myChart.getExport().getImage().getBMP().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.
try { myChart.getExport().getData().getText().save(tmpName); }
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:
Example
try { tChart1.getExport().getTemplate().toFile("/temp/chart1.tej"); } 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 Tee file from a local file source or http data source.
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); }
![]() |
![]() |