原创|行业资讯|编辑:凌霄汉|2022-04-06 16:40:46.300|阅读 158 次
概述:此次报表开发工具TeeChart Pro .NET使用教程将为大家带来如何导出和导入图表。
# 慧都年终大促·界面/图表报表/文档/IDE等千款热门软控件火热促销中 >>
相关链接:
本篇文章将会为大家讲解上一篇文章《TeeChart Pro .NET使用教程(2022):如何导出和导入图表(上)》未讲完的部分。
系列数据有四种导出格式
上述组件可能与图表系列相关联,它们可以从中将数据导出为文件、流或剪贴板。 以下示例将数据从图表系列导出到 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
Ten文件是 TeeChart 自己的用于保存 Charts 及其数据的模板格式。 修改后的图表属性与模板一起保存,并在模板导入新图表时重现。
优点:
[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。
[C#] protected override void button1_Click(object sender, System.EventArgs e) tChart1.Series.RemoveAllSeries(); Steema.TeeChart.Styles.Points points1 = new Steema.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();
从本地文件源或 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 文件仅保存对标准 Chart 定义的更改,如果目标 Chart 包含要导入的 Chart 未涉及的属性更改,则将保留原件。 一个例子是图表页脚。 如果 .ten 文件没有设置页脚而目标图表有,则页脚将在导入后通过图表显示。 这可能是一个理想的结果。 如果您希望在导入 Chart 后对导入 Chart 进行更改,这可能会对所需结果产生不利影响,那么您可以创建一个 Chart 的新实例,如下例所示:
[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
如果您想了解TeeChart for .NET正版价格,欢迎咨询
本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@pclwef.cn