Namespace: GlobFX.SwiffChartGenerator
Assembly: GlobFX.SwiffChartGenerator (in GlobFX.SwiffChartGenerator.dll)

Specifies the data (i.e. title, series values & captions, categories, etc) directly from a text file.

Visual Basic
Public Sub SetDataFromTxtFile( filename As String,
                                    seriesincolumn As Boolean,
                                    titlesinfirstrow As Boolean,
                                    titlesinfirstcolumn As Boolean ) 
C#
public void SetDataFromTxtFile( string filename,
                                     bool seriesincolumn,
                                     bool titlesinfirstrow,
                                     bool titlesinfirstcolumn ); 

Arguments

filename
A string that specifies the name of the text file that contains the data.
seriesincolumn
A boolean value that specifies whether data series are in columns or in rows.
titlesinfirstrow
A boolean value that specifies whether the first data row should be interpreted as titles (i.e. series captions or categories names).
titlesinfirstcolumn
A boolean value that specifies whether the first data column should be interpreted as titles (i.e. series captions or categories names).

Remarks

Before calling the SetDataFromTxtFile method, you must specify the separator characters used to delimit the data in the text file identified by filename. To specify the separator characters as well as separator rules, see the SetSeparators method.

If the text file identified by filename is in unicode, you must call the SetUnicode method to specify that the SetDataFromTxtFile method should treat text files as a unicode (UTF-16).

If both titlesinfirstcolumn and titlesinfirstrow are set to true then data located in the first cell (i.e. first column and first row) are interpreted as the title of the chart.

If the system fails to open the text file identified by filename, the SetDataFromTxtFile method raises an error.

Parsing Rules According to the Chart Type

Swiff Chart Generator can produce various types of charts, either Column charts, Pie charts, Line charts or even XY-Scatter charts. The chart type is always specified in the Swiff Chart style file (.scs file, see How to Create Styles to learn more about styles). For this reason, data stored in a text file are not interpreted the same way for all the chart types.

If the chart plot type is Columns, Bars or Lines then Swiff Chart Generator requires a set of individual series to display the chart. Therefore, the text data are parsed and interpreted as a set of individual series.

However, if the chart plot type is XY-Scatter or XY-Curves then Swiff Chart Generator requires a set of series pairs to display the chart. Therefore, the text data are parsed and interpreted as a set of series pairs (first series for X values, second series for Y values). In this particular case, if the number of data series in the text file is odd, then the last data series are omitted.


The following text file contains 2 series.

Series1;12;7.5;11.3;9.2;5.3
Series2;14;9.9;13.1;11.5;4.9
If the chart type is Columns, Bars or Lines
Data are interpreted as 2 individual series of values (12, 7.5, 11.3, 9.2 and 5.3) and (14, 9.9, 13.1, 11.5 and 4.9).
If the chart type is XY-Scatter or XY-Curves
Data are interpreted as a single series of XY Points (12,14), (7.5,9.9), (11.3,13.1), (9.2,11.5) and (5.3,4.9).

Sample Code

The following code sample illustrates use of the SetDataFromTxtFile method.


  1. Here is a plain ASCII text file, named data.txt that contains the data we want to apply to the chart object.

    TitleOfMyChart;North America;South America;Europe;Middle East;Asia
    Year 2006;12;7.5;11.3;9.2;5.3
    Year 2007;14;9.9;13.1;11.5;4.9
    

  2. Before importing the text file, we must specify the separator characters and set some variables.

    Visual Basic
    ' The text file has titles in columns as well as in rows
    ' The  character ";" is the character separator in text file data.txt
    Dim sep As String = ";"
    Dim ignore_mult_separators As Boolean = False
    
    ' Before going further we must specify the separators of the text file
    chart.SetSeparators(sep, ignore_mult_separators)
    
    ' Let's load the graphical layout of the chart
    chart.LoadStyle( "C:\\myStyle.scs" )
    
    ' the first text line contains the title and categories names: "TitleOfMyChart;North America;South America..."
    Dim titlesinfirstrow As Boolean = True
    
    ' the first text column contains the title and series captions: "TitleOfMyChart", "Year 2006" and "Year 2007"
    Dim titlesinfirstcolumn As Boolean = True
    
    C#
    // The text file has titles in columns as well as in rows
    // The  character ";" is the character separator in text file data.txt
    string sep= ";";
    bool ignore_mult_separators= false;
    
    // Before going further we must specify the separators of the text file
    chart.SetSeparators(sep, ignore_mult_separators);
    
    // Let's load the graphical layout of the chart
    chart.LoadStyle( "C:\\myStyle.scs" );
    
    // the first text line contains the title and categories names: "TitleOfMyChart;North America;South America..."
    bool titlesinfirstrow= true;
    
    // the first text column contains the title and series captions: "TitleOfMyChart", "Year 2006" and "Year 2007"
    bool titlesinfirstcolumn= true;
    

  3. Calling the SetDataFromTxtFile method with the parameters below...

    Visual Basic
    Dim seriesincolumns As Boolean = False;
    chart.SetDataFromTxtFile( "C:\\data.txt", seriesincolumn, titlesinfirstrow, titlesinfirstcolumn )
    C#
    bool seriesincolumns= false;
    chart.SetDataFromTxtFile( "C:\\data.txt", seriesincolumn, titlesinfirstrow, titlesinfirstcolumn );

    ...leads to the following data stored in the chart object memory:

    Title MyChartTitle
    Categories   North America South America Europe Middle East Asia
    Series 1 Year 2006 12 7.5 11.3 9.2 5.3
    Series 2 Year 2007 14 9.9 13.1 11.5 4.9

  4. However, calling the SetDataFromTxtFile method with the parameters below...

    Visual Basic
    Dim seriesincolumns As Boolean = True
    chart.SetDataFromTxtFile( "C:\\data.txt", seriesincolumn, titlesinfirstrow, titlesinfirstcolumn )
    C#
    bool seriesincolumns= true;
    chart.SetDataFromTxtFile( "C:\\data.txt", seriesincolumn, titlesinfirstrow, titlesinfirstcolumn );

    ...leads to the following data stored in the chart object memory (maybe NOT what you would expect):

    Title MyChartTitle
    Categories   Year 2006 Year 2007
    Series 1 North America 12 14
    Series 2 South America 7.5 9.9
    Series 3 Europe 11.3 13.1
    Series 4 Middle East 9.2 11.5
    Series 5 Asia 5.3 4.9

See Also

SetSeparators Method | SetUnicode Method

Applies To: Chart Object