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
BMP
PNG

Exporting data

Text, XML

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
  • BMP: BMPFormat 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.

    BMP

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

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

    Text files

    Example
                try {
                        myChart.getExport().getData().getText().save(tmpName);
                    }
    

    XML files

    Example
                try {
                        myChart.getExport().getTemplate().toXML(tmpName);
                        showSavedFile(tmpName);
                    }
    
    

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

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



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