原创|其它|编辑:郝浩|2012-07-09 01:19:00.000|阅读 1211 次
概述:本教程概述了导出不同格式的图表以及导入TeeChart中文版自带的 .ten 格式的图表模板。
# 慧都年终大促·界面/图表报表/文档/IDE等千款热门软控件火热促销中 >>
本教程概述了导出不同格式的图表以及导入TeeChart中文版自带的 .ten 格式的图表模板。
支持的格式
TeeChart所支持的导出格式。所有格式都可复制到任何一个文件夹、剪贴板或数据流中。
图片格式
数据格式
其他格式
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文件并添加colours 和 size两个参数
例如
[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都有speed和quality两个参数。
例如
[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)
Quality的值(1-100)会使文件变大,从而导致网络传输速度变慢?虽然图片质量会更好!所以您需要找到一个适合应用程序的最佳平衡点。
WMF & EMF
将“Enhanced”设为Ture就可轻松地创建增强型元文件。
例如
[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)
GIF
由于Micosoft 的.Net Framework 类库的运用,TeeChart .Net可以支持导出GIF格式的位图,特别System.Drawing.Imaging Namespace中的那些类。 时至今日对于开发者来说,他们依然不清楚在应用程序中使用这些类,是否需要从Unisys获得GIF专利的授权许可。如果还有其他疑问,我们建议您访问 Unisys Website.
例如
[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)文件。关于如何在运行时实现上述功能,以及如何添加动画到已导出图表的综合实例,可以在'Welcome !\New in Canvas\Flash "CompactCharts"'下的功能演示中找到。
四种数据导出格式:
以上的控件与图表Series有关系,他们可以导出数据到任何文件,数据流或是剪贴板。下面的实例是从图表Series中将数据导出到HTML表格中:
[C#]
private void Form1_Load(object sender, System.EventArgs e)
Random rnd = new Random();
char c = new char();
for(int i = 0; i < 10; ++i)
c = Convert.ToChar(65 + i);
bar1.Add(Convert.ToDouble(i),rnd.Next(100),c.ToString(),Color.Red);
Steema.TeeChart.Export.DataExport dataExport = new Steema.TeeChart.Export.DataExport(tChart1.Chart);
dataExport.HTML.IncludeHeader = true;
dataExport.HTML.IncludeIndex = true;
dataExport.HTML.IncludeLabels = true;
dataExport.HTML.Series = bar1;
dataExport.HTML.Save(@"C:.htm");
[VB.Net]
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim C As New Char()
Dim i As New Integer()
For i = 0 To 10
C = Convert.ToChar(65 + i)
Bar1.Add(Convert.ToDouble(i), Rnd() * 100, C.ToString(), Color.Red)
Next
Dim DataExport As New Steema.TeeChart.Export.DataExport(TChart1.Chart)
DataExport.HTML.IncludeHeader = True
DataExport.HTML.IncludeIndex = True
DataExport.HTML.IncludeLabels = True
DataExport.HTML.Series = Bar1
DataExport.HTML.Save("C:.htm")
End Sub
以上输出的随机数据集如下所示:
<table border="1">
<tr><td>Index</td><td>Text</td><td>bar1</td></tr>
<tr><td>0</td><td>A</td><td>69</td></tr>
<tr><td>1</td><td>B</td><td>93</td></tr>
<tr><td>2</td><td>C</td><td>18</td></tr>
<tr><td>3</td><td>D</td><td>88</td></tr>
<tr><td>4</td><td>E</td><td>42</td></tr>
<tr><td>5</td><td>F</td><td>33</td></tr>
<tr><td>6</td><td>G</td><td>58</td></tr>
<tr><td>7</td><td>H</td><td>43</td></tr>
<tr><td>8</td><td>I</td><td>63</td></tr>
<tr><td>9</td><td>J</td><td>49</td></tr>
</table>
Ten 文件
Ten文件是TeeChart自带的用来保存图表和数据的模板格式。
修改的图表属性将保存在模板中,当将模板导入到一个新的图表时它们就会重现。
优点:
例如
[C#]
private void button1_Click(object sender, System.EventArgs e)
saveFileDialog1.Filter = "TenFile (.ten)|*.ten";
saveFileDialog1.ShowDialog();
if(saveFileDialog1.FileName != "")
tChart1.Export.Template.IncludeData = true;
tChart1.Export.Template.Save(saveFileDialog1.FileName);
[VB.Net]
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
SaveFileDialog1.Filter = "TenFile (.ten)|*.ten"
SaveFileDialog1.ShowDialog()
If SaveFileDialog1.FileName <> "" Then
TChart1.Export.Template.IncludeData = True
TChart1.Export.Template.Save(SaveFileDialog1.FileName)
End If
End Sub
将XML导入到TeeChart
从TextBox导入XML.
例如
[C#]
protected override void button1_Click(object sender, System.EventArgs e)
tChart1.Series.RemoveAllSeries();
Steema.TeeChart.Styles.Points points1 = new Stee ma.TeeChart.Styles.Points(tChart1.Chart);
points1.Title = "Points Series";
xmlSource1.Series = points1;
xmlSource1.SeriesNode = "Points Series";
xmlSource1.Load(textBox2.Text);
tChart1.Refresh();
从URL导入XML .
例如
[C#]
protected override void button2_Click(object sender, System.EventArgs e)
tChart1.Series.RemoveAllSeries();
xmlSource1.Chart = tChart1.Chart;
xmlSource1.Load("//www.steema.com/SampleNETData.xml");
tChart1.Refresh();
导入Ten 格式文件
从本地文件源或http数据源中导入一个已保存的Tee文件
导入实例
例如
从文件中导入
[C#]
tChart1.Import.Template.LoadFileDialog();
[VB.Net]
TChart1.Import.Template.LoadFileDialog()
URL..
[C#]
tChart1.Import.Template.FromURL("//www.berneda.com/demo.ten");
[VB.Net]
TChart1.Import.Template.FromURL("//www.berneda.com/demo.ten")
Stream..
[C#]
System.IO.MemoryStream tenStream = new System.IO.MemoryStream();
tChart1.Export.Template.Save(tenStream);
tChart2.Import.Template.Load(tenStream);
[VB.Net]
Dim TenStream As New System.IO.MemoryStream()
TChart1.Export.Template.Save(TenStream)
TChart2.Import.Template.Load(TenStream)
导入图表会引起效果的改变
由于.ten文件只保存标准图表定义的改变,所以目标图表的属性变化与被导入的图表无关,而是由原始图表来执行。这是一个图表页脚的实例。如果.ten文件没有设定页脚和目标图表,那么页脚将会在图表导入后才显示。这将是一个理想的结果。如果您期望在导入图表时引起变化,它能在图表导出后逆向影响所期望的结果,那么您就能创建一个新图表例子,如下所示:
[C#]
private void Form1_Load(object sender, System.EventArgs e)
Bar bar1 = new Bar(tChart1.Chart);
bar1.FillSampleValues(20);
private void button1_Click(object sender, System.EventArgs e)
saveFileDialog1.Filter = "TenFile (.ten)|*.ten";
saveFileDialog1.ShowDialog();
if(saveFileDialog1.FileName != "")
tChart1.Export.Template.IncludeData = true;
tChart1.Export.Template.Save(saveFileDialog1.FileName);
private void button2_Click(object sender, System.EventArgs e)
tChart1.Dispose();
tChart1 = new Steema.TeeChart.TChart();
ini_Chart();
private void ini_Chart()
this.tChart1.Header.Lines = new string[] "TeeChart";
this.tChart1.Location = new System.Drawing.Point(24, 24);
this.tChart1.Name = "tChart1";
this.tChart1.Size = new System.Drawing.Size(400, 240);
this.tChart1.TabIndex = 5;
this.Controls.AddRange(new System.Windows.Forms.Control[] this.tChart1);
private void button3_Click(object sender, System.EventArgs e)
tChart1.Import.Template.LoadFileDialog();
[VB.Net]
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim Bar1 As New Steema.TeeChart.Styles.Bar(TChart1.Chart)
Bar1.FillSampleValues(20)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
SaveFileDialog1.Filter = "TenFile (.ten)|*.ten"
SaveFileDialog1.ShowDialog()
If Not SaveFileDialog1.FileName = "" Then
TChart1.Export.Template.IncludeData = True
TChart1.Export.Template.Save(SaveFileDialog1.FileName)
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
TChart1.Dispose()
TChart1 = New Steema.TeeChart.TChart()
Ini_Chart()
End Sub
Private Sub Ini_Chart()
Me.TChart1.Header.Lines = New String() "TeeChart"
Me.TChart1.Location = New System.Drawing.Point(16, 16)
Me.TChart1.Name = "TChart1"
Me.TChart1.Size = New System.Drawing.Size(400, 296)
Me.TChart1.TabIndex = 3
Me.Controls.AddRange(New System.Windows.Forms.Control() Me.TChart1)
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
TChart1.Import.Template.LoadFileDialog()
End Sub
本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@pclwef.cn
文章转载自:慧都控件网