【TeeChart Pro ActiveX教程】(十二):导入和导出图表(上)

下载TeeChart Pro ActiveX最新版本

本教程概述了以各种格式导出TeeCharts并导入TeeChart自己的.ten格式图表模板。

导出图表

可用格式

可用导出格式。可以将所有格式复制到文件或剪贴板或Stream。

图像格式

  • BMP:BitmapFormat类
  • JPEG:JPEGFormat类
  • WMF和EMF:MetafileFormat类
  • GIF:GIFFormat类
  • PNG:PNGFormat类
  • TIFF:TIFFFormat类

数据格式

  • Text:TextFormat类
  • XML:XMLFormat类
  • HTML:HTMLFormat类
  • Excel:ExcelFormat类

其他格式

ten格式是一种灵活的格式,可存储图表属性信息和(可选)图表数据。文件很小(取决于数据),非常适合网络用于更新基于实时客户端的图表。

  • TEN(TeeChart):TemplateExport类

示例导出

导出到文件是合理的,在大多数情况下,您只需要定义目标文件名。

[C#]

private void button1_Click(object sender, System.EventArgs e)  
            saveFileDialog1.Filter = "Images (*.bmp)|*.bmp|Images(*.jpg)|*.jpg|Images(*.wmf)|*.wmf|Images(*.emf)|*.emf|Images (*.gif)|*.gif|Images (*.png)|*.png|Images (*.tiff)|*.tiff"; 
            saveFileDialog1.ShowDialog(); 
            if(saveFileDialog1.FileName != "")  
                switch(saveFileDialog1.FilterIndex)  
                    case 1: 
                        tChart1.Export.Image.Bitmap.Save(saveFileDialog1.FileName); 
                        break; 
                    case 2: 
                        tChart1.Export.Image.JPEG.Save(saveFileDialog1.FileName); 
                        break; 
                    case 3: 
                        tChart1.Export.Image.Metafile.Enhanced = false; 
                        tChart1.Export.Image.Metafile.Save(saveFileDialog1.FileName); 
                        break; 
                    case 4: 
                        tChart1.Export.Image.Metafile.Enhanced = true; 
                        tChart1.Export.Image.Metafile.Save(saveFileDialog1.FileName); 
                        break; 
                    case 5: 
                        tChart1.Export.Image.GIF.Save(saveFileDialog1.FileName); 
                        break; 
                    case 6: 
                        tChart1.Export.Image.PNG.Save(saveFileDialog1.FileName); 
                        break; 
                    case 7: 
                        tChart1.Export.Image.TIFF.Save(saveFileDialog1.FileName); 
                        break; 

[VB.Net]

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 
        SaveFileDialog1.Filter = "Images (*.bmp)|*.bmp|Images(*.jpg)|*.jpg|Images(*.wmf)|*.wmf|Images(*.emf)|*.emf|Images (*.gif)|*.gif|Images (*.png)|*.png|Images (*.tiff)|*.tiff" 
        SaveFileDialog1.ShowDialog() 
        If SaveFileDialog1.FileName <> "" Then 
            Select Case SaveFileDialog1.FilterIndex 
                Case 1 
                    TChart1.Export.Image.Bitmap.Save(SaveFileDialog1.FileName) 
                Case 2 
                    TChart1.Export.Image.JPEG.Save(SaveFileDialog1.FileName) 
                Case 3 
                    TChart1.Export.Image.Metafile.Enhanced = False 
                    TChart1.Export.Image.Metafile.Save(SaveFileDialog1.FileName) 
                Case 4 
                    TChart1.Export.Image.Metafile.Enhanced = True 
                    TChart1.Export.Image.Metafile.Save(SaveFileDialog1.FileName) 
                Case 5 
                    TChart1.Export.Image.GIF.Save(SaveFileDialog1.FileName) 
                Case 6 
                    TChart1.Export.Image.PNG.Save(SaveFileDialog1.FileName) 
                Case 7 
                    TChart1.Export.Image.TIFF.Save(SaveFileDialog1.FileName) 
            End Select 
        End If 
End Sub 

导出图片

BMP

BMP文件导出具有颜色和大小的附加参数,例

[C#]

case 1: 
     Steema.TeeChart.Export.BitmapFormat bitMap = tChart1.Export.Image.Bitmap; 
     bitMap.Height = 500; 
     bitMap.Width = 700; 
     bitMap.Monochrome = true; 
     bitMap.Save(saveFileDialog1.FileName); 
     break; 

[VB.Net]

Case 1 
     Dim BitMap As Steema.TeeChart.Export.BitmapFormat = TChart1.Export.Image.Bitmap 
     BitMap.Height = 500 
     BitMap.Width = 700 
     BitMap.Monochrome = True 
     BitMap.Save(SaveFileDialog1.FileName) 

JPEG

JPEG文件导出现在具有SaveToFile和SaveToStream的速度和质量参数,例

[C#]

case 2: 
Steema.TeeChart.Export.JPEGFormat jPEG = tChart1.Export.Image.JPEG; 
     jPEG.GrayScale = true; 
     jPEG.Height = 500; 
     jPEG.Width = 700; 
     jPEG.Quality = 100; 
     jPEG.Save(saveFileDialog1.FileName); 
     break; 

[VB.Net]

Case 2 
Dim JPEGf As Steema.TeeChart.Export.JPEGFormat = TChart1.Export.Image.JPEG 
     JPEGf.Height = 500 
     JPEGf.Width = 700 
     JPEGf.GrayScale = True 
     JPEGf.Quality = 100 
     JPEGf.Save(SaveFileDialog1.FileName) 

质量值(从1到100)将使文件更大,从而更慢地通过网络传输 - 但质量更好!您需要根据自己的应用决定最佳平衡。通过将“Enhanced”设置为True,可以简单地创建

WMF和EMF

增强型图元文件,例

[C#]

case 3: 
     Steema.TeeChart.Export.MetafileFormat metaFile = tChart1.Export.Image.Metafile; 
     metaFile.Height = 500; 
     metaFile.Width = 700; 
     metaFile.Enhanced = false; 
     metaFile.Save(saveFileDialog1.FileName); 
     break; 

[VB.Net]

Case 3 
     Dim MetaFile As Steema.TeeChart.Export.MetafileFormat = TChart1.Export.Image.Metafile 
     MetaFile.Height = 500 
     MetaFile.Width = 700 
     MetaFile.Enhanced = False 
     MetaFile.Save(SaveFileDialog1.FileName)

由于Microsoft的.Net Framework类库,特别是 System.Drawing.Imaging命名空间中包含的类, GIF TeeChart for .Net能够支持以GIF格式导出位图,例

[C#]

case 5: 
     Steema.TeeChart.Export.GIFFormat gIF = tChart1.Export.Image.GIF; 
     gIF.Height = 500; 
     gIF.Width = 700; 
     gIF.ColorReduction = Steema.TeeChart.Export.GIFFormat.GIFColorReduction.GrayScale; 
     gIF.Save(saveFileDialog1.FileName); 
     break; 

[VB.Net]

Case 5 
     Dim GIF As Steema.TeeChart.Export.GIFFormat = TChart1.Export.Image.GIF 
     GIF.Height = 500 
     GIF.Width = 700 
     GIF.ColorReduction = Steema.TeeChart.Export.GIFFormat.GIFColorReduction.GrayScale 
     GIF.Save(SaveFileDialog1.FileName) 

PNG

PNG格式保留了GIF格式的许多优点,但也提供了超出GIF格式的功能。PNG改进了GIF逐步显示图像的能力; 也就是说,当图像通过网络连接到达时,显示更好和更好的图像近似值,例:

[C#]

case 6: 
     Steema.TeeChart.Export.PNGFormat pNG = tChart1.Export.Image.PNG; 
     pNG.Compression = 100; 
     pNG.GrayScale = true; 
     pNG.Height = 500; 
     pNG.Width = 700; 
     pNG.Save(saveFileDialog1.FileName); 
     break; 

[VB.Net]

Case 6 
     Dim PNGf As Steema.TeeChart.Export.PNGFormat = TChart1.Export.Image.PNG 
     PNGf.Compression = 100 
     PNGf.GrayScale = True 
     PNGf.Height = 500 
     PNGf.Width = 700 
     PNGf.Save(SaveFileDialog1.FileName) 

TIFF

TIFF是一种灵活且可扩展的格式,受到各种平台和图像处理应用程序的支持。 例

[C#]

case 7: 
     Steema.TeeChart.Export.TIFFFormat tIFF = tChart1.Export.Image.TIFF; 
     tIFF.Compression = Steema.TeeChart.Export.TIFFFormat.TIFFCompression.LZW; 
     tIFF.Height = 500; 
     tIFF.Width = 700; 
     tIFF.Save(saveFileDialog1.FileName); 
     break; 

[VB.Net]

Case 7 
     Dim TIFF As Steema.TeeChart.Export.TIFFFormat = TChart1.Export.Image.TIFF 
     TIFF.Compression = Steema.TeeChart.Export.TIFFFormat.TIFFCompression.LZW 
     TIFF.Height = 500 
     TIFF.Width = 700 
     TIFF.Save(SaveFileDialog1.FileName) 

Adobe Flex/Flash/SWF

TeeChart现在可以导出到Adobe Flex脚本文件(* .mxml),然后可以通过Flex的免费编译器(mxmlc.exe)进行编译,以创建* .swf(Flash)文件。有关如何在运行时实现此功能的详细示例,包括如何向导出的图表添加动画的详细信息。

 

你可能感兴趣的:(产品)