ZedGraph - 强制所有图形窗格大小相同

时间:2013-02-12 19:17:56

标签: vb.net winforms zedgraph

我使用ZedGraph控件(zgc)创建单独的堆积条形图并将其显示在单个堆叠列中,如下图所示。

我遇到的问题是我无法控制控件中显示的窗格数量,因为这是由列表框中的项目数决定的。似乎控件的默认属性允许图形窗格的高度根据控件中显示的窗格数量而变化。

zgc设置为dock = fill在面板控件中,该控件在表单中设置为dock = fill。我想强制图形窗格为静态高度,当需要时,当图形窗格的数量超过窗体的高度时,面板中会出现垂直滚动条。我怎样才能实现这一目标?我创建和填充zgc的代码发布在图像下方。

enter image description here

Private Sub CreateGraph(ByVal dat As Date)

    Dim count As Integer = 0
    Dim master As MasterPane = zgc.MasterPane
    master.Fill = New Fill(Color.FromArgb(180, 180, 180), Color.FromArgb(180, 180, 180), 45.0F)
    master.PaneList.Clear()
    master.Title.IsVisible = True
    master.Title.Text = "Workload for " & dat.ToShortDateString()
    master.Margin.All = 10
    master.InnerPaneGap = 5
    master.IsCommonScaleFactor = False

    For Each mach As String In lbMach.Items
        rowCount = 0
        Dim myPaneT As New GraphPane(New Rectangle(10, 10, 10, 10), "", "Time in Minutes", mach)
        myPaneT.Fill.IsVisible = False
        myPaneT.Chart.Fill = New Fill(Color.White, Color.White, 45.0F)
        myPaneT.BaseDimension = 3.0F
        myPaneT.XAxis.Title.IsVisible = False
        myPaneT.XAxis.Scale.IsVisible = False

        myPaneT.XAxis.Scale.Min = 0
        myPaneT.XAxis.Scale.Max = (MeiSettings.WrkHrs * 60)
        myPaneT.Legend.IsVisible = True
        myPaneT.Border.IsVisible = False
        myPaneT.Title.IsVisible = False
        myPaneT.XAxis.MajorTic.IsOutside = False
        myPaneT.XAxis.MinorTic.IsOutside = False
        myPaneT.XAxis.MajorGrid.IsVisible = True
        myPaneT.XAxis.MinorGrid.IsVisible = True
        myPaneT.Margin.All = 1

        If count = lbMach.Items.Count - 1 Then
            myPaneT.XAxis.Title.IsVisible = True
            myPaneT.XAxis.Scale.IsVisible = True
            myPaneT.Margin.Bottom = 10
        End If

        If count > 0 Then
            myPaneT.YAxis.Scale.IsSkipLastLabel = True
        End If

        myPaneT.YAxis.MinSpace = 20
        myPaneT.Y2Axis.MinSpace = 20

        Dim dt As DataTable = ItemsByMachineDT(mach, dat)
        Dim myCurve As BarItem

        If dt.Rows.Count > 0 Then
            Dim profName As String = Nothing
            Dim timeDur() As Double
            For Each dr As DataRow In dt.Rows
                If profName = dr("PRO").ToString() Then
                    timeDur = {((Convert.ToDouble(dr("QTY")) / Convert.ToDouble(dr("MPM"))))}
                Else
                    timeDur = {((Convert.ToDouble(dr("QTY")) / Convert.ToDouble(dr("MPM")) + Convert.ToDouble(dr("Time"))))}
                End If

                myCurve = myPaneT.AddBar(dr("JOB").ToString & " - " & dr("PRO").ToString(), timeDur, Nothing, BarColor(rowCount))

                If MeiSettings.IsGradient = True Then
                    myCurve.Bar.Fill = New Fill(BarColor(rowCount), Color.White, BarColor(rowCount), 90.0F)
                Else
                    myCurve.Bar.Fill = New Fill(BarColor(rowCount), BarColor(rowCount), BarColor(rowCount), 90.0F)
                End If

                rowCount += 1
                profName = dr("PRO").ToString()
            Next
        End If

        myPaneT.YAxis.MajorTic.IsBetweenLabels = True
        myPaneT.YAxis.Type = AxisType.Text
        myPaneT.BarSettings.Type = BarType.Stack
        myPaneT.BarSettings.Base = BarBase.Y
        master.Add(myPaneT)
        count += 1
    Next

    zgc.IsShowPointValues = True

    Using g As Graphics = Me.CreateGraphics()
        master.SetLayout(g, PaneLayout.SingleColumn)
        master.AxisChange(g)
    End Using

End Sub

1 个答案:

答案 0 :(得分:0)

获取每个GraphPane的控制权:

    GraphPane temp = zgc.MasterPane.PaneList.ElementAt(ind); //ind => index of the graphpane in zedgraphcontrol

设置静态高度n宽度ZedgraphControl:

    zgc.Size = new Size(Width,Height);

设置滚动条ZedgraphControl的可见性:

    zgc.IsShowHScrollBar = true;
    zgc.IsShowVScrollBar = true;