Tutorial 12 - Exporting and Importing Charts |
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.
Contents |
Exporting Charts
Available formats Import |
Available Export formats:
(BMP) | CopyToClipboardBitmap |
(WMF) | CopyToClipboardMetafile |
BMP | SaveToBitmapFile |
TEE (TeeChart) | SaveChartToFile |
JPG | SaveChartToJPEGFile |
WMF | SaveToMetafile |
EMF | SaveToMetaFileEnh |
Example
ChartExport(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. 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.
Tee files are TeeChart's own template format for saving Charts and their data. All Chart properties are saved with the template and reproduced when the template is imported to a new Chart. They are very small in size, that offers an advantage over graphics formats (Quicker). The other advantage is that the destination Chart for the template is 'live', it can be zoomed and scrolled and have properties modified.
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); 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.
![]() |
![]() |