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;
        }
 
 
 
轉載自http://www.cnblogs.com/w2011/p/3196206.html
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章