Contents page 
  Previous | Next 
 

Tutorial 9 - Exporting and Importing Charts


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

Available formats

Exporting Images

JPEG
GIF
PNG

Exporting data

Text, XML, HTML, XLS

TeeChart's 'Tee' template and data export import format

Tee files

Import

Importing Tee format files
Example import Tee file


Exporting Charts

Available Export formats

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
  • 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.

  • TEN (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.

    TEE (TeeChart) SaveChartToFile

    At runtime you can display the export dialogue by using the

    Chart TeeExport

    method.

    Example

    TeeExport(Self,TheChart);
    

    Example export

    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

    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.

    GIF

    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);
                } 

    PNG

    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);
                } 

    Exporting data

    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

    TeeChart's 'Tee' template and data export/import format

    Tee files

    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
    

    Import

    Importing XML from a URL.

    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);
                }
    

    Importing Tee format files

    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 Imports

    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.






    © 1996-2006 Steema Software SL. All rights reserved.