Search Results for

    Show / Hide Table of Contents

    Data sources for the Gantt chart

    The GanttDataSource class exists to connect the chart to the data source. By default, it is already contained in the chart, but does not have any data in it.

    GanttDataSource

    The class allows to build a hierarchical structure based on table sources (System.Data.DataSet, System.Array) using standard mechanism DataBinding, load existing data set from XML or CSV files, as well as set data manually.

    To load data from files there are methods ReadXmlDta and ReadCsvData.

    GanttDataSource source = new GanttDataSource();
    
    // Loads dataset from xml file
    source.ReadXmlData(path_to_xml_file);
    

    After (or before) loading the data, you need to specify which fields will be used to define the values.

    Suppose you have an Xml file whose node has the following form:

    <record text="Release" StartDate="3/30/2021" EndDate="3/31/2021" Resource="SomeResourceName"/>
    

    To load the data from this xml we need the following code:

    source.NameMember = "text";
    source.StartDateMember = "StartDate";
    source.EndDateMember = "EndDate";
    source.ResourceMember = "text";
    

    It is not necessary to use ResourceMember. If it is not specified, all records will have an index of 0 and will use the first color in the palette when rendering.

    It's also possible to use a simple list as data. To do this, fill the records collection with GanttRecord elements, each with fields Text, StartDate, EndDate and Index to define the text, start date, end date and index of the record.

    In the following example we create an instance of GanttDataSource and set it as the data source.

    GanttDataSource source = new GanttDataSource();
    
    // Creating a new list
    List<GanttRecords> records = new List<GanttRecords>();
    
    // Filling the list with items
    records.Add(new GanttRecord()
    {
        Text="Task1",
        StartDate = new DateTime(day: 1, month: 1, year: 2021),
        EndDate = new DateTime(day: 10, month: 1, year: 2021),
        Index = 0
    });
    records.Add(new GanttRecord()
    {
        Text="Task2",
        StartDate = new DateTime(day: 10, month: 1, year: 2021),
        EndDate = new DateTime(day: 20, month: 1, year: 2021),
        Index = 1
    });
    records.Add(new GanttRecord()
    {
        Text="Task3",
        StartDate = new DateTime(day: 20, month: 1, year: 2021),
        EndDate = new DateTime(day: 31, month: 1, year: 2021),
        Index = 2
    });
    
    // Set the list as the data source
    source.DataSource = records;
    

    Note that this method does not need to specify which fields will be used to define values.

    Back to top © 2021-2022 Copyright Fast Reports Inc.