Sunburst Chart > Quick Start |
This quick start is intended to guide you through a step-by-step process of creating a simple Sunburst application and running the same in Visual Studio.
To quickly get started with Sunburst chart and observe how it appears on running the application, follow these steps:
The following image displays how a basic Sunburst chart appears after completing the steps mentioned above.
In this step, you first create a class DataService that generates random sales data for four quarters, namely Q1, Q2, Q3, and Q4 in 2013, 2014, and 2015. Next, you bind Sunburst chart to the created class using the DataSource property provided by the FlexPie class. Then, you specify numeric values and labels for the Sunburst slices using the Binding and the BindingName property, respectively of the FlexPie class.
Imports System.Collections.Generic Imports System.Linq Imports System.Text Imports System.Threading.Tasks Namespace SunburstQuickStart Class DataService Private rnd As New Random() Shared _default As DataService Public Shared ReadOnly Property Instance() As DataService Get If _default Is Nothing Then _default = New DataService() End If Return _default End Get End Property Public Shared Function CreateFlatData() As List(Of FlatDataItem) Dim rnd As Random = Instance.rnd 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 FlatDataItem)() Dim yearLen = Math.Max(CInt(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 = False years.ForEach(Function(y) Dim i = years.IndexOf(y) Dim addQuarter = rnd.NextDouble() > 0.5 If Not quarterAdded AndAlso i = years.Count - 1 Then addQuarter = True End If If addQuarter Then quarterAdded = True times.ForEach(Function(q) Dim addMonth = rnd.NextDouble() > 0.5 Dim idx As Integer = times.IndexOf(q) Dim quar As String = "Q" + (idx + 1).ToString() If addMonth Then q.ForEach(Function(m) items.Add(New FlatDataItem() With { .Year = y, .Quarter = quar, .Month = m, .Value = rnd.[Next](30, 40) }) End Function) Else items.Add(New FlatDataItem() With { .Year = y, .Quarter = quar, .Value = rnd.[Next](80, 100) }) End If End Function) Else items.Add(New FlatDataItem() With { .Year = y.ToString(), .Value = rnd.[Next](80, 100) }) End If End Function) Return items End Function End Class End Namespace
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SunburstQuickStart { class DataService { Random rnd = new Random(); static DataService _default; public static DataService Instance { get { if (_default == null) { _default = new DataService(); } return _default; } } public static List<FlatDataItem> CreateFlatData() { Random rnd = Instance.rnd; 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<FlatDataItem> items = new List<FlatDataItem>(); 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; } if (addQuarter) { quarterAdded = true; times.ForEach(q => { var addMonth = rnd.NextDouble() > 0.5; int idx = times.IndexOf(q); var quar = "Q" + (idx + 1); if (addMonth) { q.ForEach(m => { items.Add(new FlatDataItem() { Year = y, Quarter = quar, Month = m, Value = rnd.Next(30, 40) }); }); } else { items.Add(new FlatDataItem() { Year = y, Quarter = quar, Value = rnd.Next(80, 100) }); } }); } else { items.Add(new FlatDataItem() { Year = y.ToString(), Value = rnd.Next(80, 100) }); } }); return items; } } }
Imports SunburstQuickStart.SunburstQuickStart Partial Public Class Form1 Inherits Form Public Sub New() InitializeComponent() ' specify the data source Sunburst1.DataSource = DataService.CreateFlatData() ' specify the field containing values for pie slices Sunburst1.Binding = "Value" ' specify the fields contaning labels for pie slices and legend Sunburst1.BindingName = "Year,Quarter,Month" ' set the data label content Sunburst1.DataLabel.Content = "{name}" ' set the data label position Sunburst1.DataLabel.Position = C1.Chart.PieLabelPosition.Inside End Sub End Class Public Class FlatDataItem Public Property Year() As String Get Return m_Year End Get Set m_Year = Value End Set End Property Private m_Year As String Public Property Quarter() As String Get Return m_Quarter End Get Set m_Quarter = Value End Set End Property Private m_Quarter As String Public Property Month() As String Get Return m_Month End Get Set m_Month = Value End Set End Property Private m_Month As String Public Property Value() As Double Get Return m_Value End Get Set m_Value = Value End Set End Property Private m_Value As Double End Class
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace SunburstQuickStart { public partial class Form1 : Form { public Form1() { InitializeComponent(); // specify the data source sunburst1.DataSource = DataService.CreateFlatData(); // specify the field containing values for pie slices sunburst1.Binding = "Value"; // specify the fields contaning labels for pie slices and legend sunburst1.BindingName = "Year,Quarter,Month"; // set the data label content sunburst1.DataLabel.Content = "{name}"; // set the data label position sunburst1.DataLabel.Position = C1.Chart.PieLabelPosition.Inside; } } public class FlatDataItem { public string Year { get; set; } public string Quarter { get; set; } public string Month { get; set; } public double Value { get; set; } } }
Press F5 to run the application and observe how Sunburst chart appears.