|
■No86436 (mako さん) に返信
若干違うかもしれませんが
以下のようにNullの要素を追加するとそこだけデータがプロットされません。
時間の項目に文字列を使うのはグラフ上扱いにくいのでグラフ用のDataTableを
用意されて時間項目はDateTime型にされた方がよいです。
DataTable1つの場合はDataSetを使う必要はなくDataTable直接でよいです。
_tbl = New DataTable()
With _tbl.Columns
.Add("t", GetType(DateTime))
.Add("y1", GetType(Integer))
.Add("y2", GetType(Integer))
End With
With _tbl.Rows
.Add(Date.Today.AddHours(8).AddMinutes(45), 30, 2)
.Add(Date.Today.AddHours(9).AddMinutes(0), 20, 3)
.Add(Date.Today.AddHours(9).AddMinutes(15), 20, 3)
.Add(Date.Today.AddHours(9).AddMinutes(30), 5, 4)
.Add(Date.Today.AddHours(9).AddMinutes(45), 10, 8)
.Add(Date.Today.AddHours(10).AddMinutes(0), 15, 10)
.Add(Date.Today.AddHours(10).AddMinutes(15), DBNull.Value, DBNull.Value)
.Add(Date.Today.AddHours(10).AddMinutes(30), DBNull.Value, DBNull.Value)
.Add(Date.Today.AddHours(11).AddMinutes(15), 5, 3)
.Add(Date.Today.AddHours(11).AddMinutes(30), 20, 15)
.Add(Date.Today.AddHours(11).AddMinutes(45), 5, 3)
.Add(Date.Today.AddHours(12).AddMinutes(0), 10, 8)
.Add(Date.Today.AddHours(12).AddMinutes(15), 20, 10)
End With
Chart1.DataSource = _tbl
With Chart1.ChartAreas(0)
With .AxisX
.Minimum = Date.Today.AddHours(8).AddMinutes(45).ToOADate
.Maximum = Date.Today.AddHours(12).AddMinutes(15).ToOADate
.IntervalType = DataVisualization.Charting.DateTimeIntervalType.Minutes
.Interval = 30
Dim isFirst = True
For Each row In _tbl.Select("", "t")
Dim dt = row.Field(Of Date)("t")
If isFirst OrElse dt.Minute = 0 OrElse dt.Minute = 30 Then
With .CustomLabels.Add(dt.AddMinutes(-3).ToOADate, dt.AddMinutes(3).ToOADate, dt.ToString("HH:mm"))
.RowIndex = 0
End With
End If
isFirst = False
Next
End With
End With
With Chart1.Series(0)
.XValueMember = "t"
.YValueMembers = "y1"
End With
With Chart1.Series.Add("")
.ChartType = SeriesChartType.Line
.EmptyPointStyle.Color = Color.Transparent
.XValueMember = "t"
.YValueMembers = "y2"
End With
|