原創|使用教程|編輯:龔雪|2014-01-09 11:13:03.000|閱讀 1599 次
概述:在使用XGantt進行任務管理特別是生產任務管理時,你可能常常需要在甘特圖中顯示全局視圖模式和詳細視圖模式。本文將為你講解全局視圖模式與詳細視圖模式在XGantt中的使用。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
在使用甘特圖進行多任務管理的時候,用戶通常都希望既能看到成千上萬個任務的全局顯示,又能實時對某個任務的詳情進行快速查看。然而很多時候,當需要在重重任務中查看某一任務時,它卻迷失在汪洋大海中難以發現。為了在圖中找這小小的幾個像素,卻要耐心等待整體畫面加載直至完成。
其實,解決這一問題有很多方法,今天我們就以VARCHART XGantt為例,介紹一種方法:全局視圖模式與詳細視圖模式的使用。
在全局視圖模式中,任務條的形狀是寬度不一的矩形,每個任務條的邊界是隱藏的。多個相鄰的任務條一起構成了一個單一的活動板塊。整體畫面是整齊而緊湊的(如下圖)。
全局視圖模式(展示了將近300個任務):
由全局視圖模式切換到詳細視圖模式,默認的XGantt右鍵菜單需要替換為一個新的包含“Build subdiagram”(生成子圖)和“Restore full diagram”(恢復全圖)選項的菜單。當轉到子圖時,用戶選擇查看的任務將顯示相關細節,而其他未選的任務則由“ActiveNodeFilter”隱藏起來。另外,時標部分被限制在盡可能小的范圍內,任務條的邊界顯示出來,并配有一個標簽。這些任務條被調整到一定寬度,一字排列,當鼠標指在某個任務上時,工具提示框將顯示任務詳情(如下圖)。
詳細視圖模式:
選擇右鍵菜單中的“Restore full diagram”(恢復全圖)項,則又可以回到全局視圖模式了。
所需C#代碼:
private void contextMenuItem_BuildSubDiagram_Click(object sender, EventArgs e) { VcLayer layer = vcGantt1.LayerCollection.LayerByName("Tasks"); layer.LineType = VcLineType.vcLineType0; layer.Shape = VcLayerShape.vcSWRoundedRectangleLayer; layer.Format.get_FormatField(0).TextDataFieldIndex = vcGantt1.DetectFieldIndex("Tasks", "ID"); layer.Height = 1500; vcGantt1.ActiveNodeFilter = vcGantt1.FilterCollection.MarkedNodesFilter; VcNodeCollection visibleNodes = vcGantt1.NodeCollection; visibleNodes.SelectNodes(VcSelectionType.vcAllVisible); optimizeTimescaleStartEndEx(visibleNodes, 20); vcGantt1.FitRangeIntoView(vcGantt1.TimeScaleStart, vcGantt1.TimeScaleEnd, 0); vcGantt1.ScrollToNodeLine(visibleNodes.FirstNode(), VcVerticalAlignment.vcVerCenterAligned); } private void contextMenuItem_RestoreFullDiagram_Click(object sender, EventArgs e) { VcLayer layer = vcGantt1.LayerCollection.LayerByName("nodes"); layer.LineType = VcLineType.vcNone; layer.Shape = VcLayerShape.vcRectangleLayer; layer.Format.get_FormatField(0).TextDataFieldIndex = -1; layer.Height = 500; vcGantt1.ActiveNodeFilter = null; vcGantt1.OptimizeTimeScaleStartEnd(720); vcGantt1.TimeScaleCollection.Active.get_Section(0).UnitWidth = 400; } private void vcGantt1_VcNodeRightClicking(object sender, VcNodeClickingEventArgs e) { e.ReturnStatus = VcReturnStatus.vcRetStatNoPopup; myContextMenu.Show(MousePosition); } private void vcGantt1_VcDiagramRightClicking(object sender, VcDiagramClickingEventArgs e) { e.ReturnStatus = VcReturnStatus.vcRetStatNoPopup; myContextMenu.Show(MousePosition); } private void optimizeTimescaleStartEndEx(VcNodeCollection nodes, int marginsInMinutes) { if(nodes.Count > 0) { DateTime earliestDate = new DateTime(2222, 1, 1); DateTime latestDate = new DateTime(1900,1,1); foreach (VcNode node in nodes) { //Earliest Date DateTime t = (DateTime)node.get_DataField(8); if (t < earliestDate) { earliestDate = t; } //Latest Date int d = Int32.Parse(node.get_DataField(7).ToString());^ t = vcGantt1.CalendarCollection.Active.AddDuration(t, d); if (t > latestDate) { latestDate = t; } } vcGantt1.TimeScaleStart = earliestDate.AddMinutes(-marginsInMinutes); vcGantt1.TimeScaleEnd = latestDate.AddMinutes(marginsInMinutes); } } //The VcToolTipTextSupplying property has to be activated to display tool tips. private void vcGantt1_VcToolTipTextSupplying(object sender, VcToolTipTextSupplyingEventArgs e) { vcGantt1.ToolTipDuration = 25000; if(e.HitObjectType == VcObjectType.vcObjTypeNodeInDiagram) { VcNode node = (VcNode)e.HitObject; e.Text = "ID: " + node.ID + "\n"; e.Text += "Machine: " + node.get_DataField(1) + "\n"; } else if (e.HitObjectType == VcObjectType.vcObjTypeTimeScale) { e.Text = "Preset Timescale: " + vcGantt1.TimeScaleCollection.Active.Name; } }
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉載自:慧都控件網