| ■No83343 (KY さん) に返信
提示されたサンプルに手を加えたものです。
Dim dat As DataTable = New DataTable
With dat.Columns
.Add("年月日時分", GetType(Date)) ' X軸 <---- 実際は"2017/03/16 16:31"、"2017/03/16 16:32"、・・・ などの"年月日時分"です。
.Add("数量", GetType(Integer)) ' Y軸
End With
Dim cRandom As New System.Random() ' Random クラスの新しいインスタンスを生成する
Dim iResult1 As Integer = cRandom.Next(13, 186) ' 実際は"年月日時分"ですが分かり易く 13以上 186 未満の乱数を取得し開始を決めている
Dim baseDate = Date.Today.AddDays(-iResult1)
For i = iResult1 To iResult1 + 100
Dim iResult2 As Integer = cRandom.Next(1, 100) ' "数量" (1 以上 100 未満の乱数を取得する)
dat.Rows.Add(baseDate.AddMinutes(i), iResult2)
Next
Chart1.DataSource = dat
Chart1.Series.Clear()
Dim oresen = Chart1.Series.Add("棒グラフ")
With oresen
.ChartType = DataVisualization.Charting.SeriesChartType.Column
.XValueMember = "年月日時分" ' X軸
.YValueMembers = "数量" ' Y軸
.IsVisibleInLegend = False
End With
With Chart1.ChartAreas(0)
With .AxisX
.LabelStyle.Format = "yyyy/MM/dd HH:mm"
.IntervalType = DataVisualization.Charting.DateTimeIntervalType.Minutes
.Interval = 15
End With
End With
|