/// <summary>
/// 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>
''' 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