Devexpress Gantt 應用


甘特圖屬於甘特系列瀏覽次數(也稱為時間或時間軸圖表)。此視圖顯示橫條沿時間軸。每個條形代表一個單獨的事件的開始和結束的值,

因此,這些圖是用來跟蹤各種活動的時間范圍內(例如計划,利用各種資源,審查該項目的完成項目管理等)。這種圖表類型是非常有用的,

當有必要從不同系列上面顯示。

  protected override void OnLoad(EventArgs e)
        {
            ChartControl overlappedGanttChart = new ChartControl();

            var series1 = new Series("計划", ViewType.Gantt);
            var series2 = new Series("進度", ViewType.Gantt);

           //設置值的類型為 時間
            series1.ValueScaleType = ScaleType.DateTime;
            series2.ValueScaleType = ScaleType.DateTime;

            // 添加數據
            series1.Points.Add(new SeriesPoint("市場分析", new DateTime[] { 
    new DateTime(2006, 8, 16), new DateTime(2006, 8, 23) }));
            series1.Points.Add(new SeriesPoint("功能規划", new DateTime[] { 
    new DateTime(2006, 8, 23), new DateTime(2006, 8, 26) }));
            series1.Points.Add(new SeriesPoint("開發規划", new DateTime[] { 
    new DateTime(2006, 8, 26), new DateTime(2006, 9, 26) }));
            series1.Points.Add(new SeriesPoint("測試與Bug維護", new DateTime[] { 
    new DateTime(2006, 9, 26), new DateTime(2006, 10, 10) }));

            series2.Points.Add(new SeriesPoint("市場分析", new DateTime[] { 
    new DateTime(2006, 8, 16), new DateTime(2006, 8, 23) }));
            series2.Points.Add(new SeriesPoint("功能規划", new DateTime[] { 
    new DateTime(2006, 8, 23), new DateTime(2006, 8, 26) }));
            series2.Points.Add(new SeriesPoint("開發規划", new DateTime[] { 
    new DateTime(2006, 8, 26), new DateTime(2006, 9, 10) }));

            overlappedGanttChart.Series.AddRange(new Series[] { series1, series2 });

            // 訪問視圖類型特定的選項的系列
            ((GanttSeriesView)series1.View).BarWidth = 0.6;
            ((GanttSeriesView)series2.View).BarWidth = 0.3;

            // 訪問特定類型的選項 diagram.
            GanttDiagram myDiagram = (GanttDiagram)overlappedGanttChart.Diagram;
            myDiagram.AxisY.Interlaced = true;
            myDiagram.AxisY.GridSpacing = 10;
            myDiagram.AxisY.Label.Angle = -30;
            myDiagram.AxisY.DateTimeOptions.Format = DateTimeFormat.MonthAndDay;
            ((GanttSeriesView)series1.View).LinkOptions.ArrowHeight = 7;
            ((GanttSeriesView)series1.View).LinkOptions.ArrowWidth = 11;
            for (int i = 1; i < series1.Points.Count; i++)
            {
                series1.Points[i].Relations.Add(series1.Points[i - 1]);
            }

            // 添加進度線.
            ConstantLine progress =
            new ConstantLine("當前的進度", new DateTime(2006, 9, 10));
            progress.ShowInLegend = false;
            progress.Title.Alignment = ConstantLineTitleAlignment.Far;
            myDiagram.AxisY.ConstantLines.Add(progress);

            // 調整 legend.
            overlappedGanttChart.Legend.AlignmentHorizontal =
                LegendAlignmentHorizontal.Right;

            // 添加標題
            overlappedGanttChart.Titles.Add(new ChartTitle());
            overlappedGanttChart.Titles[0].Text = "項目計划";

            overlappedGanttChart.Dock = DockStyle.Fill;
            this.Controls.Add(overlappedGanttChart);
        }
 //設置進度        
void SetProgressState(DateTime dateTime) { if (dateTime > rightAxisLimit) dateTime = rightAxisLimit; if (CompletedSeries != null && PlannedSeries != null) { CompletedSeries.Points.BeginUpdate(); CompletedSeries.Points.Clear(); foreach (SeriesPoint point in PlannedSeries.Points) { DateTime plannedStartDate = point.DateTimeValues[0]; if (DateTime.Compare(plannedStartDate, dateTime) >= 0) continue; DateTime plannedFinishDate = point.DateTimeValues[1]; DateTime completedFinishDate; if (DateTime.Compare(dateTime, plannedFinishDate) > 0) completedFinishDate = plannedFinishDate; else completedFinishDate = dateTime; CompletedSeries.Points.Add(new SeriesPoint(point.Argument, new DateTime[] { plannedStartDate, completedFinishDate })); } CompletedSeries.Points.EndUpdate(); } if (HasConstantLine) ProgressLine.AxisValue = dateTime; }

部分代碼來自於官網、在這里做個備注


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM