【问题标题】:ZedGraph - Force all graph panes to be the same sizeZedGraph - 强制所有图形窗格的大小相同
【发布时间】:2013-02-28 03:10:23
【问题描述】:

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

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

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

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

【问题讨论】:

  • 为了澄清事情,我已经玩过父面板和zedgraph控件的对接。我已将父面板设置为 autoscroll=true 并将 zgc 设置为 dock=top。我尝试根据图表中显示的窗格数量设置 zgc 高度。就滚动而言,这可以按预期工作,但是,无论控件的高度如何,图形窗格的大小仍然不一致。因此,我仍在尝试弄清楚如何为每个图形窗格设置特定的高度。

标签: vb.net winforms zedgraph


【解决方案1】:

获取每个 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;

【讨论】:

    猜你喜欢
    • 2013-03-24
    • 1970-01-01
    • 2013-10-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-22
    • 2017-01-08
    • 1970-01-01
    相关资源
    最近更新 更多