FlexChart for WinForms
Chart Types / Specialized Charts / Sunburst
In This Topic
    Sunburst
    In This Topic

    Sunburst, also known as a multi-level pie chart, is ideal for visualizing multi-level hierarchical data depicted by concentric circles. The circle in the center represents the root node surrounded by the rings representing different levels of hierarchy. Rings are divided based on their relationship with the parent slice with each of them either divided equally or proportional to a value. For instance, you can use sunburst to display sales over past few years or to display makes or models of a product.

    Create a Sunburst Chart

    FlexChart for WinForms provides sunburst chart through a stand alone Sunburst control which is represented by the Sunburst class. The control appears as a pie chart when dropped on the form until it is provided with a hierarchical data using the DataSource property provided by the FlexPie class. This class also provides Binding and BindingName properties for setting numeric values and labels of the sunburst slices. You can also specify the angle from where you want to start drawing the slices in the clock wise direction by setting the StartAngle property. FlexChart also provides properties to create following variations of sunburst chart:

    Doughnut Sunburst Chart

    Exploded Sunburst Chart

    Reversed Sunburst Chart

    To create a sunburst chart using FlexChart:

    At design-time

    1. Drag and drop the Sunburst control to the form.
    2. Right click the Sunburst control on form to open the Properties window.
    3. Set the data source using the DataSource property.
    4. Configure the chart by setting the Binding and BindingName property.
    5. Set the ChildItemsPath property to name of the property that contains child items.

    Using code

    To create a sunburst chart through code, the first step after initializing the control is to clear the default series. Set up the data source through the DataSource property and configure the chart by setting the Binding and BindingName property. Also, set the ChildItemsPath property to generate child items in hierarchical data.

    //Specify the field containing values for pie slices
    sunburst1.Binding = "Value";
    
    //Specify the fields containing labels for pie slices and legend
    sunburst1.BindingName = "Year,Quarter,Month";
    
    //Specify the fields containing values for child pie slices 
    sunburst1.ChildItemsPath = "Items";
    
    //Set the data label position
    sunburst1.DataLabel.Position = PieLabelPosition.Center;
    
    //Set the data label content
    sunburst1.DataLabel.Content = "{name}";
    
    //Set the tooltip label content
    sunburst1.ToolTip.Content = "In {name} Sales : {value}\nShare : {P:0}%";
    
    //Specify the data source
    sunburst1.DataSource = GetSunburstData();
    
    //Set the data label content
    sunburst1.Header.Content = "Sales over the years";
            ''' <summary>
            ''' Method for initializing SunburstChart
            ''' </summary
            Private Sub SetupSunburstChart()
    #Region "SetupChart"
                'Specify the field containing values for pie slices
                sunburst1.Binding = "Value"
    
                'Specify the fields containing labels for pie slices and legend
                sunburst1.BindingName = "Year,Quarter,Month"
    
                'Specify the fields containing values for child pie slices 
                sunburst1.ChildItemsPath = "Items"
    
                'Set the data label position
                sunburst1.DataLabel.Position = PieLabelPosition.Center
    
                'Set the data label content
                sunburst1.DataLabel.Content = "{name}"
    
                'Set the tooltip label content
                sunburst1.ToolTip.Content = "In {name} Sales : {value}" & vbLf & "Share : {P:0}%"
    
                'Specify the data source
                sunburst1.DataSource = GetSunburstData()
    
                'Set the data label content
                sunburst1.Header.Content = "Sales over the years"

    Note that the above sample code uses a custom method named GetSunburstData to supply data to the chart. You can set up the data source as per your requirements.

    /// <summary>
    /// Method for creating data for SunburstChart
    /// </summary>
    Random rnd = new Random();
    public List<HierarchicalDataItem> GetSunburstData()
    {
        List<string> years = new List<string>();
        List<List<string>> times = new List<List<string>>()
        {
            new List<string>() { "Jan", "Feb", "Mar"},
            new List<string>() { "Apr", "May", "June"},
            new List<string>() { "Jul", "Aug", "Sep"},
            new List<string>() { "Oct", "Nov", "Dec" }
        };
    
        List<HierarchicalDataItem> items = new List<HierarchicalDataItem>();
        var yearLen = Math.Max((int)Math.Round(Math.Abs(5 - rnd.NextDouble() * 10)), 3);
        int currentYear = DateTime.Now.Year;
        for (int i = yearLen; i > 0; i--)
        {
            years.Add((currentYear - i).ToString());
        }
        var quarterAdded = false;
    
        years.ForEach(y =>
        {
            var i = years.IndexOf(y);
            var addQuarter = rnd.NextDouble() > 0.5;
            if (!quarterAdded && i == years.Count - 1)
            {
                addQuarter = true;
            }
            var year = new HierarchicalDataItem() { Year = y };
            if (addQuarter)
            {
                quarterAdded = true;
                times.ForEach(q =>
                {
                    var addMonth = rnd.NextDouble() > 0.5;
                    int idx = times.IndexOf(q);
                    var quar = "Q" + (idx + 1);
                    var quarters = new HierarchicalDataItem() { Year = y, Quarter = quar };
                    if (addMonth)
                    {
                        q.ForEach(m =>
                        {
                            quarters.Items.Add(new HierarchicalDataItem()
                            {
                                Year = y,
                                Quarter = quar,
                                Month = m,
                                Value = rnd.Next(20, 30)
                            });
                        });
                    }
                    else
                    {
                        quarters.Value = rnd.Next(80, 100);
                    }
                    year.Items.Add(quarters);
                });
            }
            else
            {
                year.Value = rnd.Next(80, 100);
            }
            items.Add(year);
        });
    
        return items;
    }
    ''' <summary>
    ''' Method for creating data for SunburstChart
    ''' </summary>
    Private rnd As New Random()
    Public Function GetSunburstData() As List(Of HierarchicalDataItem)
        Dim years As New List(Of String)()
        Dim times As New List(Of List(Of String))() From {
            New List(Of String)() From {
                "Jan",
                "Feb",
                "Mar"
            },
            New List(Of String)() From {
                "Apr",
                "May",
                "June"
            },
            New List(Of String)() From {
                "Jul",
                "Aug",
                "Sep"
            },
            New List(Of String)() From {
                "Oct",
                "Nov",
                "Dec"
            }
        }
    
        Dim items As New List(Of HierarchicalDataItem)()
        Dim yearLen As Integer = Math.Max(CInt(Math.Truncate(Math.Round(Math.Abs(5 - rnd.NextDouble() * 10)))), 3)
        Dim currentYear As Integer = DateTime.Now.Year
        For i As Integer = yearLen To 1 Step -1
            years.Add((currentYear - i).ToString())
        Next
        Dim quarterAdded As Boolean = False
    
        years.ForEach(Function(y)
                          Dim i As Integer = years.IndexOf(y)
                          Dim addQuarter As Boolean = rnd.NextDouble() > 0.5
                          If Not quarterAdded AndAlso i = years.Count - 1 Then
                              addQuarter = True
                          End If
                          Dim year As HierarchicalDataItem = New HierarchicalDataItem() With {
            .Year = y
        }
                          If addQuarter Then
                              quarterAdded = True
                              times.ForEach(Function(q)
                                                Dim addMonth As Boolean = rnd.NextDouble() > 0.5
                                                Dim idx As Integer = times.IndexOf(q)
                                                Dim quar As String = "Q" & (idx + 1)
                                                Dim quarters As HierarchicalDataItem = New HierarchicalDataItem() With {
                 .Year = y,
                 .Quarter = quar
            }
                                                If addMonth Then
                                                    q.ForEach(Function(m)
                                                                  quarters.Items.Add(New HierarchicalDataItem() With {
                 .Year = y,
                     .Quarter = quar,
                     .Month = m,
                     .Value = rnd.[Next](20, 30)
                })
    
                                                              End Function)
                                                Else
                                                    quarters.Value = rnd.[Next](80, 100)
                                                End If
                                                year.Items.Add(quarters)
    
                                            End Function)
                          Else
                              year.Value = rnd.[Next](80, 100)
                          End If
                          items.Add(year)
    
                      End Function)
    
        Return items
    End Function
    See Also