Search Results for

    Show / Hide Table of Contents

    Creating a chart

    To create a chart from a program, use the following code:

    // Create a TreeMap chart
    TreeMap treeMap = new TreeMap();
    

    Then connect a data source to the chart. There are various data sources for hierarchical charts and you can read about them in the chapter "Hierarchical Data Sources".

    Let us create the data source, fill in the information, and connect the data source:

    HierarchicalRecordsSource treeMapRecordsSource = new HierarchicalRecordsSource();
    // Start of initialization - allows to disable the call of source change events
    treeMapRecordsSource.BeginInit();
    // Creating a "Bakery products" record. The constructor for creating a record may not take a value if it is a record containing child nodes
    HierarchicalRecord r = new HierarchicalRecord("Bakery products");
    // Creating child records. The text and value are passed to the constructor
    r.Children.Add(new HierarchicalRecord("Ciabatta", 3));
    r.Children.Add(new HierarchicalRecord("Bread", 5));
    r.Children.Add(new HierarchicalRecord("Croissant", 1));
    
    // Adding a parent record to the list of source records 
    treeMapRecordsSource.Records.Add(r);
    
    // Similarly, create other records
    r = new HierarchicalRecord("Alcohol");
    r.Children.Add(new HierarchicalRecord("Wine", 6));
    r.Children.Add(new HierarchicalRecord("Whiskey", 2));
    r.Children.Add(new HierarchicalRecord("Beer", 5));
    treeMapRecordsSource.Records.Add(r);
    
    r = new HierarchicalRecord("Dairy products");
    r.Children.Add(new HierarchicalRecord("Yoghurt", 3));
    r.Children.Add(new HierarchicalRecord("Milk", 4));
    treeMapRecordsSource.Records.Add(r);
    
    // End of the source initialization
    treeMapRecordsSource.EndInit();
    // Connecting to the data source of the list chart 
    treeMap.DataSource = treeMapRecordsSource;
    

    After you connect the data source, the chart will look like this:

    FastReport Business Graphics - Create From Code

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