-1

我正在寻找在 vb.net windows 应用程序中开发甘特图应用程序。我想知道是否有任何免费的第三方工具或一些演示应用程序,以便我可以了解它。

4

2 回答 2

3

您可以在 VB.NET 中使用GDI API轻松绘制甘特图。看看codeproject文章。

于 2012-08-30T11:27:06.100 回答
2

您可以使用 System.Windows.Forms.DataVisualization.Charting 来执行此操作。这是一些示例代码。

    Dim newSeries As New Series

    openConn()'opens the connection
    openRS("SELECT * FROM Data")'pull data from database
    Do Until rs.EOF
        newSeries = New Series'create a new dataSeries
        yPlot1 = CDbl(rs.Fields("Start Date").Value.ToOADate())'set beginning of bar
        yPlot2 = CDbl(DateAdd(DateInterval.Day, rs.Fields("Duration").Value, rs.Fields("Start Date").Value).ToOADate())'set end of bar
        newSeries.ChartType = SeriesChartType.RangeBar
        newSeries.YValuesPerPoint = 2
        newSeries.CustomProperties = "DrawSideBySide=false"
        xOrdinal = rs.Fields("Ordinal").Value
        newSeries.Points.AddXY(xOrdinal, yPlot1, yPlot2)
        newSeries.Points(0).ToolTip = rs.Fields("Task Name").Value.ToString
        newSeries.Name = rs.Fields("Task Name").Value.ToString
        newSeries.Points(0).Color = Color.FromKnownColor(DirectCast([Enum].Parse(GetType(KnownColor), CStr(rs.Fields("Color").Value.ToString)), KnownColor))
        newSeries.Points(0).AxisLabel = rs.Fields("Ordinal Name").Value.ToString
        seriesList.Add(newSeries)
        rs.MoveNext()
    Loop

    rs = Nothing
    cn.Close()
    cn = Nothing

    Chart1.Series.Clear()
    For Each plotSeries As Series In seriesList
        Chart1.Series.Add(plotSeries)
    Next
    Chart1.ChartAreas(0).AxisX.Interval = 1
    Chart1.ChartAreas(0).AxisY.Interval = 7
    Chart1.ChartAreas(0).AxisX.IsReversed = True
    Chart1.ChartAreas(0).AxisY.IsStartedFromZero = False
    Chart1.ChartAreas(0).AxisY.IsMarginVisible = False
    Chart1.ChartAreas(0).AxisY.IntervalType = DateTimeIntervalType.Days

    Chart1.ChartAreas(0).AxisY.Minimum = CDbl(#4/1/2012#.ToOADate())
    Chart1.ChartAreas(0).AxisY.Maximum = CDbl(#6/30/2012#.ToOADate())
    Chart1.ChartAreas(0).AxisY.LabelStyle.Format = "ddd M/d"

    Chart1.Update()

您将需要在您的表单 (Chart1) 上有一个图表控件。当然,您的数据可能会有所不同,但这可能会为您提供您缺少的步骤。您还可以查看以下文档以获取更多详细信息。

http://wiki.visualwebgui.com/pages/images/6/6a/MSChartsGanttChartAndPrinting.pdf

于 2012-08-30T13:29:36.710 回答