注册 登录
编程论坛 VB.NET论坛

求助:Teechart画柱状图只显示一个柱子

zhangzhen 发布于 2011-07-21 22:55, 819 次点击
我的部分代码如下
程序代码:
myChart.Chart.Series.Clear()
        myChart.Chart.Header.Text = ComboBox6.SelectedItem & "统计柱状图"
        '定义Y轴属性
        Dim i, j, k As Integer
        Dim max As Double
        While i < DataGridView1.RowCount
            If DataGridView1.Rows(i).Cells(2).Value IsNot DBNull.Value Then
                max = DataGridView1.Rows(i).Cells(2).Value
                j = i
                Exit While
            End If
        End While

        For k = j To DataGridView1.RowCount - 2

            If DataGridView1.Rows(k + 1).Cells(2).Value IsNot DBNull.Value Then
                If DataGridView1.Rows(k + 1).Cells(2).Value >= max Then
                    max = DataGridView1.Rows(k + 1).Cells(2).Value
                End If
            End If
        Next
        '以上求最大值max
        With myChart.Chart.Axes.Left
            .Title.Text = ComboBox2.SelectedItem
            .Title.Angle = 360
            .Automatic = True
            .Maximum = max
            .Minimum = 0

        End With
        '定义X轴属性
        With myChart.Chart.Axes.Bottom
            .Automatic = True
            .Title.Text = vbCrLf & "时间点"
            .Labels.Style = AxisLabelStyle.Text
            .DateTimeDefaultFormat(1)
            .SetMinMax(0, DataGridView1.Rows(DataGridView1.RowCount - 1).Cells(0).Value)
        End With
        Dim bar_Initiative As Bar
        bar_Initiative = New Bar()

        myChart.Chart.Series.Add(bar_Initiative)
        With bar_Initiative
            .ShowInLegend = True
            .Depth = 38
            .CustomBarWidth = 5
            .Color = Color.Blue
            .BarStyle = BarStyles.Rectangle
            .Marks.Visible = True
            .Marks.ShapeStyle = Drawing.TextShapeStyle.Rectangle
            .Marks.Transparent = True
            .Marks.Font.Color = Color.Blue
        End With
        Randomize()

        Dim myArray() As Double = New Double() {}

        For i1 As Integer = j To DataGridView1.RowCount - 1
            ReDim Preserve myArray(i1)
            If DataGridView1.Rows(i1).Cells(2).Value IsNot DBNull.Value Then
                myArray(i1) = DataGridView1.Rows(i1).Cells(2).Value
            End If
        Next
        For i2 As Integer = j To DataGridView1.RowCount - 1
            If DataGridView1.Rows(i2).Cells(2).Value IsNot DBNull.Value Then
                bar_Initiative.Add(myArray(i2))
                myChart.Chart.Axes.Bottom.Labels.Items.Add(i2, DataGridView1.Rows(i2).Cells(0).Value & " " & DataGridView1.Rows(i2).Cells(1).Value)
            End If
        Next
为什么只显示第一个柱子呢?如图:

1 回复
#2
zhangzhen2011-07-21 22:55
只有本站会员才能查看附件,请 登录
1