/// <summary>
/// StatisticalChartのデータを作成するメソッド
/// </summary>
private DataSource _dataHelper = new DataSource().Instance;
private Random rnd = new Random();
public List<CategoricalPoint> GetMonthAxisDataSource()
{
List<CategoricalPoint> data = new List<CategoricalPoint>();
int i = 0;
foreach (string month in _dataHelper.Months.Take(12))
{
data.Add(new CategoricalPoint { Name = month, Value = i });
i++;
}
return data;
}
public List<CityDataItem> GetTemperatureData(string[] cities, bool monthly = false, int count = 30, bool isFahrenheit = false)
{
var data = new List<CityDataItem>();
var startDate = new DateTime(2017, 1, 1);
foreach (string city in cities)
{
var dataItem = new CityDataItem() { Name = city };
for (int i = 0; i < count; i++)
{
var temp = new Temperature();
DateTime date;
if (monthly)
date = startDate.AddMonths(i);
else
date = startDate.AddDays(i);
temp.Date = date;
if (date.Month <= 8)
temp.HighTemp = rnd.Next(3 * date.Month, 8 * date.Month);
else
temp.HighTemp = rnd.Next((13 - date.Month - 2) * date.Month, (13 - date.Month) * date.Month);
temp.LowTemp = temp.HighTemp - rnd.Next(6, 8);
temp.Precipitation = (date.Month < 4 || date.Month > 8) ? rnd.Next(100, 150) : rnd.Next(150, 200);
if (isFahrenheit) temp.HighTemp = temp.HighTemp * 1.8 + 32;
dataItem.Data.Add(temp);
}
data.Add(dataItem);
}
return data;
}
''' <summary>
''' StatisticalChartのデータを作成するメソッド
''' </summary>
Private _dataHelper As DataSource = New DataSource().Instance
Private rnd As New Random()
Public Function GetMonthAxisDataSource() As List(Of CategoricalPoint)
Dim data As New List(Of CategoricalPoint)()
Dim i As Integer = 0
For Each month As String In _dataHelper.Months.Take(12)
data.Add(New CategoricalPoint() With {
.Name = month,
.Value = i
})
i += 1
Next
Return data
End Function
Public Function GetTemperatureData(cities As String(), Optional monthly As Boolean = False, Optional count As Integer = 30, Optional isFahrenheit As Boolean = False) As List(Of CityDataItem)
Dim data As List(Of CityDataItem) = New List(Of CityDataItem)()
Dim startDate As DateTime = New DateTime(2017, 1, 1)
For Each city As String In cities
Dim dataItem As CityDataItem = New CityDataItem() With {
.Name = city
}
For i As Integer = 0 To count - 1
Dim temp As Temperature = New Temperature()
Dim [date] As DateTime
If monthly Then
[date] = startDate.AddMonths(i)
Else
[date] = startDate.AddDays(i)
End If
temp.[Date] = [date]
If [date].Month <= 8 Then
temp.HighTemp = rnd.[Next](3 * [date].Month, 8 * [date].Month)
Else
temp.HighTemp = rnd.[Next]((13 - [date].Month - 2) * [date].Month, (13 - [date].Month) * [date].Month)
End If
temp.LowTemp = temp.HighTemp - rnd.[Next](6, 8)
temp.Precipitation = If(([date].Month < 4 OrElse [date].Month > 8), rnd.[Next](100, 150), rnd.[Next](150, 200))
If isFahrenheit Then
temp.HighTemp = temp.HighTemp * 1.8 + 32
End If
dataItem.Data.Add(temp)
Next
data.Add(dataItem)
Next
Return data
End Function