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

object.SetDataFromTxtFile filename, seriesincolumn, titlesinfirstrow, titlesinfirstcolumn 

Arguments

object
Required. A Chart object.
filename
Required. A string that specifies the name of the text file that contains the data.
seriesincolumn
Required. A boolean value that specifies whether data series are in columns or in rows.
titlesinfirstrow
Required. A boolean value that specifies whether the first data row should be interpreted as titles (i.e. series captions or categories names).
titlesinfirstcolumn
Required. 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).

VBScript Sample Code

The following VBScript code sample illustrates use of the SetDataFromTxtFile method in an ASP page.


  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.

    'The text file has titles in columns as well as in rows
    'The  character ";" is the character separator in text file data.txt
    sep= ";"
    ignoremultseparators= false
    
    'Before going further we must specify the separators of the text file
    chart.SetSeparators sep, ignoremultseparators
    
    '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..."
    titlesinfirstrow= true
    
    'the first text column contains the title and series captions: "TitleOfMyChart", "Year 2006" and "Year 2007"
    titlesinfirstcolumn= true
    

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

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

    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

SetDataFromQuery Method | SetSeparators Method | SetUnicode Method

Applies To: Chart Object