Difference between revisions of "NETTutorial12"

From Steema Software Reference Wiki
Jump to: navigation, search
Line 4: Line 4:
 
|
 
|
 
[[Image:tchnet.jpg]]
 
[[Image:tchnet.jpg]]
| align="RIGHT" | <font size="2">  [[NETTutorials|Contents page]]<br />[[NETTutorial11|Previous]] | [[NETTutorial13|Next]]
+
| align="RIGHT" | <font size="2">  [[TeeChart for .NET|Contents page]]<br />[[NETTutorial11|Previous]] | [[NETTutorial13|Next]]
  
 
</font>
 
</font>
Line 110: Line 110:
 
</center>
 
</center>
 
----
 
----
© 1998-2013 Steema Software SL. All rights reserved.
+
© 1998-2014 Steema Software SL. All rights reserved.

Revision as of 16:26, 20 December 2013

Tchnet.jpg

Contents page
Previous | Next


Tutorial12 - Exporting and Importing Charts

This tutorial is overviews exporting TeeCharts in various formats and importing TeeChart's own .ten format Chart templates.  

Contents

Exporting Charts
     Available formats
     Example export

Exporting Images
     BMP
     JPEG
     WMF & EMF
     GIF
     PNG
     TIFF
     Flex/Flash/SWF

Exporting data]
     Text, XML, HTML, XLS

TeeChart's 'Ten' template and data export import format
     Ten files

Import
     Importing XML into TeeChart
     Importing Ten format files
     Example import Ten file
     Effect of changes made in importing Chart
     Other datasources


Exporting Charts

Available formats

Available Export formats. All formats may be copied to either a file or Clipboard or to a Stream.

Image formats

  • BMP: BitmapFormat Class
  • JPEG: JPEGFormat Class
  • WMF & EMF: MetafileFormat Class
  • GIF: GIFFormat Class
  • PNG: PNGFormat Class
  • TIFF: TIFFFormat Class

Data formats

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

Other formats

  • TEN (TeeChart): TemplateExport Classs

Ten 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.

Example export
Exporting to a file is reasonably straightforward, in most cases you just need to define the destination filename.
[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


Exporting Images

BMP
BMP file export has additional parameters for colours and size.
Example
[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 file export now has parameters for speed and quality for both SaveToFile and SaveToStream.
Example
[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)

WMF & EMF
Enhanced Metafiles are simply created by setting "Enhanced" to True.
Example
[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
TeeChart for .Net is able to support the exportation of bitmaps in GIF format thanks to Microsoft's .Net Framework Class Library, specifically those classes contained in the [ms-help://MS.VSCC/MS.MSDNVS/cpref/html/frlrfsystemdrawingimaging.htm System.Drawing.Imaging Namespace]. To this day it remains unclear whether developers who implement these classes in their applications need to license the GIF patent from Unisys or not. Our best suggestion, if in doubt, is to visit the Unisys Website.
Example



[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



[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



[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


Exporting data


Formats


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



[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

















TeeChart's 'Ten' template and </div>data export/import format

Ten files



  • Ten files are very small in size, in most cases that offers an advantage
        over pure graphic formats (qicker).
  • The destination Chart for the template is 'live', it can be zoomed and scrolled and have
      its properties modified.
  • Data may optionally be included with the ten template according to your preference.


[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


Import

Importing XML into TeeChart


Example 
[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();
        


Example 
[C#]
protected override void button2_Click(object sender, System.EventArgs e)
            tChart1.Series.RemoveAllSeries();
            xmlSource1.Chart = tChart1.Chart;
            xmlSource1.Load("http://www.steema.com/SampleNETData.xml");

            tChart1.Refresh();
        

Importing Ten format files



Example Imports

Example 


[C#] 
tChart1.Import.Template.LoadFileDialog();
[VB.Net]
TChart1.Import.Template.LoadFileDialog()




[C#] 
tChart1.Import.Template.FromURL("http://www.berneda.com/demo.ten");
[VB.Net]
TChart1.Import.Template.FromURL("http://www.berneda.com/demo.ten")




[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)

Effect of changes made in importing 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

Other datasources

NETTutorial8-Database Access tutorial


PREVIOUS

NEXT


© 1998-2014 Steema Software SL. All rights reserved.