标题:求助:Teechart画柱状图只显示一个柱子
取消只看楼主
zhangzhen
Rank: 2
等 级:论坛游民
帖 子:92
专家分:27
注 册:2011-3-4
结帖率:100%
 问题点数:0 回复次数:1 
求助:Teechart画柱状图只显示一个柱子
我的部分代码如下
程序代码:
 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
为什么只显示第一个柱子呢?如图:

搜索更多相关主题的帖子: 柱子 柱状图 color 
2011-07-21 22:55
zhangzhen
Rank: 2
等 级:论坛游民
帖 子:92
专家分:27
注 册:2011-3-4
得分:0 
2011-07-21 22:55



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-345831-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.100279 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved