Contents page Previous | Next |
This tutorial is 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.
Available Export formats. All formats may be copied to either a file or Clipboard. Some formats may be copied to Stream.
Image formats
(BMP) | CopyToClipboardBitmap |
(WMF) | CopyToClipboardMetafile |
BMP | TBMPExportFormat |
JPEG | SaveChartToJPEGFile |
WMF | TEMFExportFormat.Enhanced (false) |
EMF | TEMFExportFormat |
GIF | TGIFExportFormat |
PNG | TPNGExportFormat |
PCX | TPCXExportFormat |
VML (HTML) | TVMLExportFormat |
TPDFExportFormat | |
SVG | TSVGExportFormat |
EPS | TEPSExportFormat |
Flex(Flash) | TFlexExportFormat |
VRML 3D | TVRMLExportFormat |
XAML (WPF) | TXAMLExportFormat |
Data formats
Text | TSeriesDataText |
XML | TSeriesDataXML |
HTML | TSeriesDataHTML |
Excel | TSeriesDataXLS |
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, Chart1 );
Exporting to a file is reasonable straightforward, in most cases you just need to define the destination filename.
Example:
if SaveDialog1.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. The Export method has not been included natively for TeeChart to avoid the memory overhead for non-JPEG applications.
Example
// You need to include the Delphi JPEG unit in the Uses section of your project // Pass the name of the Chart to this function. We've fixed the parameters here. // In the demo they are presented as options for the user. // Place a Chart (Chart1) on a Form and populate it with data. procedure TForm1.BitBtn1Click(Sender: TObject); begin With GetChartJPEG(Chart1) do try SaveToFile('c:\temp\myJPEGChart.jpg'); { <-- save the JPEG to disk } finally Free; { <-- free the temporary JPEG object } end; end; Function GetChartJPEG(AChart:TCustomChart):TJPEGImage; var tmpBitmap:TBitmap; begin result:=TJPEGImage.Create; { <-- create a TJPEGImage } tmpBitmap:=TBitmap.Create; { <-- create a temporary TBitmap } try tmpBitmap.Width :=AChart.Width; { <-- set the bitmap dimensions } tmpBitmap.Height:=AChart.Height; { draw the Chart on the temporary Bitmap... } AChart.Draw(tmpBitmap.Canvas,Rect(0,0,tmpBitmap.Width,tmpBitmap.Height)); { set the desired JPEG options... } With result do begin GrayScale :=False; ProgressiveEncoding :=True; CompressionQuality :=50; // % 0 - 100 PixelFormat :=jf24bit; // or jf8bit ProgressiveDisplay :=True; Performance :=jpBestQuality; // or jpBestSpeed Scale :=jsFullSize; // or jsHalf, jsQuarter, jsEighth Smoothing :=True; { Copy the temporary Bitmap onto the JPEG image... } Assign(tmpBitmap); end; finally tmpBitmap.Free; { <-- free the temporary Bitmap } end; end;
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 support is included with TeeChart courtesy of Anders Melander's Delphi GIFImage classes ((c) 1997-99 Anders Melander). Full documentation for the GIF classes are outside the scope of TeeChart's own documentation. Anders has donated GIFImage to the Jedi project who now co-ordinate documentation and support for it.
Example using TeeChart dialogue
Uses TeeGIF, TeExport; procedure TGIFExportForm.Button1Click(Sender: TObject); begin TeeSavePanel(TGIFExportFormat,Chart1); end;
Example by code
Uses TeeGIF, GIFImage; procedure TForm1.Button1Click(Sender: TObject); var tmpGIF : TGIFImage; begin tmpGIF:=TGIFImage.Create; With tmpGIF do begin Compression:=gcLZW; DitherMode:=dmStucki; ColorReduction:=rmQuantizeWindows; Assign(Chart1.TeeCreateBitmap(Chart1.Color,Rect(0,0,Chart1.Width,Chart1.Height))); SaveToFile('c:\tempCharts\Chart1.gif'); end; end;
To use PNG image format the LPng.DLL is required in \Windows\System folder or path. PNG provides a compressed image format that is supported by
the principle browsers.
Example
Uses TeePNG, TeExport; procedure TPNGExportForm.Button1Click(Sender: TObject); begin TeeSavePanel(TPNGExportFormat,Chart1); end;
The TeeStore unit includes the definition of the TSeriesData component and its descendants:
Text | TSeriesDataText |
XML | TSeriesDataXML |
HTML | TSeriesDataHTML |
Excel | TSeriesDataXLS (pre 2024 Excel xls) and TSeriesDataXLSObject (later versions of Excel for xlsx files) |
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 |
uses TeeExcelSource try xlsexp := TSeriesDataXLSObject.Create(Chart1); xlsexp.IncludeHeader := True; xlsexp.IncludeIndex := True; xlsexp.SaveToFile('c:\temp\myExcelFile.xlsx'); finally xlsexp.Free; end;
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 With SaveDialog1 do begin Filter:='Teefiles|*.tee'; if Execute then SaveChartToFile(Chart1,SaveDialog1.FileName,True); end;
Import a saved Tee file from a local file source or http data source.
Example
// Import from file procedure TForm1.Button1Click(Sender: TObject); var tmpChart : TCustomChart; begin Chart1.Free; // Assuming Chart1 is already on the Form tmpChart:=TChart.Create(Self); With OpenDialog1 do begin Filter:= 'Teefiles|*.tee'; if Execute then LoadChartfromFile(tmpChart,OpenDialog1.FileName); end; Chart1 := tmpChart as TChart; With Chart1 do begin Parent:=Self; end; end;
You may also import a TeeChart file from URL, LoadChartFromURL.
Tee files may be imported from remote web sources via the LoadChartFromURL method or the ChartWebSource component. CSV data may be imported via the TSeriesTextSource component. Please see the Internet Applications tutorial for more information.
For information about data import from other database information sources please see the Database Access tutorial.