C# と VB.NET の質問掲示板

ASP.NET、C++/CLI、Java 何でもどうぞ

ログ内検索
  • キーワードを複数指定する場合は 半角スペース で区切ってください。
  • 検索条件は、(AND)=[A かつ B] (OR)=[A または B] となっています。
  • [返信]をクリックすると返信ページへ移動します。
キーワード/ 検索条件 /
検索範囲/ 強調表示/ ON (自動リンクOFF)
結果表示件数/ 記事No検索/ ON
大文字と小文字を区別する

No.86530 の関連記事表示

<< 0 >>
■86530  Re[15]: ChartのX軸のタイトル表示
□投稿者/ mako -(2018/02/08(Thu) 23:29:02)
    No86528 (shu さん) に返信
          
          '間
                If Not isFirst2 Then
                    For i = 1 To 2
                        ret.Rows.Add(x, DBNull.Value, DBNull.Value, DBNull.Value) : x += 5
                    Next
                End If
                isFirst2 = False
    
    この部分で 間(空白) を付けてるのですよね?
    なので、 IF文で、row("マーク") が  "*" か " " かの 条件判定が出来ないものかと思ったのです。
    
    もちろんそれに合わせてデータでの  '*' マークも付けるものとして。
    
    
    Public Class Form1
        Private Structure datF
            Dim Jikoku As String      '時刻 (実際は "2018/01/30 16:30:00" などの日付も入った文字列)
            Dim Suu1 As Integer       '数量1
            Dim Suu2 As Integer       '数量2
            Dim mark As String        'とりあえずは連続した時間の最初のデータのみに '*' マークを付ける。
        End Structure
        Dim Uridat(500) As datF
        Dim datS As Integer
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            ' 1分間隔のサンプルデータをを成
            datS = -1
    
            ' 8:10〜8:45           
            For i = 10 To 45        ' 8:10〜8:45
                datS = datS + 1
                Uridat(datS).mark = " "
                'Uridat(datS).Jikoku = "8:" & Str(i)  '時刻
                Uridat(datS).Jikoku = $"8:{i:00}"    '時刻
                Uridat(datS).Suu1 = i * 10           '数量1
                Uridat(datS).Suu2 = i * 5            '数量2 
    
                Uridat(datS).mark = " "
                If i = 10 Then
                    Uridat(datS).mark = "*"          ' とりあえずはデータの最初にのみ "*" マーク を付けてみる。
                End If
            Next
    
            ' 10:20〜11:55
            For i = 0 To 59        ' 10:20〜10:59
                datS = datS + 1
                'Uridat(datS).Jikoku = "10:" & Str(i)   '時刻
                Uridat(datS).Jikoku = $"10:{i:00}"     '時刻
                Uridat(datS).Suu1 = i + 100            '数量1
                Uridat(datS).Suu2 = i + 20             '数量2
                Uridat(datS).mark = " "
    
                If i = 0 Then
                    Uridat(datS).mark = "*"            '  とりあえずはデータの最初にのみ "*" マーク を付けてみる。
                End If
            Next
            For i = 0 To 55        ' 11:00〜11:55
                datS = datS + 1
                'Uridat(datS).Jikoku = "11:" & Str(i)   '時刻
                Uridat(datS).Jikoku = $"11:{i:00}"     '時刻
                Uridat(datS).Suu1 = i + 100            '数量1
                Uridat(datS).Suu2 = i + 20             '数量2
    
                Uridat(datS).mark = " "               '  とりあえずはデータの最初ではないので"*" マークは付けないことにする
            Next
    
            '====   Chart1   ====
            Dim ds As New DataSet
            Dim dt As New DataTable
            Dim dtRow As DataRow
    
            '列の作成
            With dt.Columns
                .Add("時刻", GetType(String))
                .Add("数量1", GetType(Integer))
                .Add("数量2", GetType(Integer))
                .Add("マーク", GetType(String))
            End With
            ds.Tables.Add(dt)
    
            'データのセット
            For i = 0 To datS
                dtRow = ds.Tables(0).NewRow
                dtRow(0) = Uridat(i).Jikoku    '時刻
                dtRow(1) = Uridat(i).Suu1      '数量1
                dtRow(2) = Uridat(i).Suu2      '数量2
                dtRow(3) = Uridat(i).mark      'マーク
    
                ds.Tables(0).Rows.Add(dtRow)
            Next
    
            'Chart に表示するデータソースを設定
            Dim min = -1
            Dim max = -1
            Dim intr = 30
            Dim tbl = GetChartDs(ds, intr, min, max)
            Chart1.DataSource = tbl.Select("", "x")
            Chart1.Series.Clear()
            '
            With Chart1.ChartAreas(0)
                With .AxisX
                    .Minimum = min
                    .Maximum = max
                    .Interval = 5
                    For Each row In tbl.Select("", "時刻")
                        Dim null = row.IsNull("数量1")
                        If null Then Continue For
                        Dim d = row.Field(Of Date)("時刻")
                        Dim x = row.Field(Of Integer)("x")
                        With .CustomLabels.Add(x - 2, x + 2, d.ToString("HH:mm"))
                            .RowIndex = 0
                        End With
                    Next
                End With
            End With
    
            Dim ore = Chart1.Series.Add("折れ線")
            With ore
                .ChartType = DataVisualization.Charting.SeriesChartType.Line
                .EmptyPointStyle.SetDefault(True)
                '.XValueMember = "時刻"
                .XValueMember = "x"
                .YValueMembers = "数量1"
            End With
    
            Dim bou = Chart1.Series.Add("棒グラフ")
            With bou
                .ChartType = DataVisualization.Charting.SeriesChartType.Column
                '.XValueMember = "時刻"
                .XValueMember = "x"
                .YValueMembers = "数量2"
            End With
        End Sub
    
        Private Function GetChartDs(Src As DataSet, IntrMin As Integer,
                                    ByRef Min As Integer, ByRef Max As Integer) As DataTable
            Dim ret As New DataTable()
            Min = Nothing
            Max = Nothing
    
            With ret.Columns()
                .Add("x", GetType(Integer))
                .Add("時刻", GetType(DateTime))
                .Add("数量1", GetType(Integer))
                .Add("数量2", GetType(Integer))
                .Add("マーク", GetType(String))
            End With
    
            Dim x = 1
            Min = x
            x = 5
    
            '一番左にスペース
            'ret.Rows.Add(x, DBNull.Value, DBNull.Value, DBNull.Value) : x += 5   '特に必要はないようにも。
    
            Dim isFirst2 = True
            For Each itm In (From r In Src.Tables(0).Select()
                             Let d = Function(s As String) As Date
                                         Dim d2 As Date = Nothing
                                         If Date.TryParseExact(s, {"HH:mm", "HH: mm", "H:m"}, Nothing, Nothing, d2) Then
                                             Return d2
                                         Else
                                             Return CDate(Nothing)
                                         End If
                                     End Function(r.Field(Of String)("時刻"))
                             Let h = d.Hour
                             Order By d
                             Group By h Into rows = Group)
                '間
                If Not isFirst2 Then
                    For i = 1 To 2
                        ret.Rows.Add(x, DBNull.Value, DBNull.Value, DBNull.Value) : x += 5
                    Next
                End If
                isFirst2 = False
    
                Dim hour = itm.h
                Dim isFirst = True
                For Each rowItm In itm.rows
                    Dim row = rowItm.r
                    Dim d = rowItm.d
                    Dim disp = False
                    If isFirst Then disp = True : isFirst = False
                    If Not disp Then
                        If d.Minute Mod IntrMin = 0 Then
                            disp = True
                        End If
                    End If
    
                    If disp Then
                        ret.Rows.Add(x, d, row("数量1"), row("数量2"))
                        x += 5
                    End If
                Next
            Next
            Max = x
            ret.AcceptChanges()
            Return ret
        End Function
    End Class
記事No.86333 のレス /過去ログ148より / 関連記事表示
削除チェック/



<< 0 >>

パスワード/

- Child Tree -