커스텀 바 스타일로 작업합니다

개요

Microsoft Project에서 Gantt 차트보기를 통해 사용자는 사용자 정의 막대 스타일를 정의하여 시각화를 개선하거나 특정 유형의 작업을 강조 할 수 있습니다. 여기에는 바 모양 (시작, 중간, 끝), 사용자 정의 색상 추가, 모양 조정 및 작업 표시 줄 주변의 텍스트 레이블 구성이 포함됩니다.

aspose.tasks for .net은 ‘GanttbarStyle’클래스를 통해이 수준의 사용자 정의를 지원합니다. 이를 통해 개발자는 각 작업 (또는 작업 그룹)이 렌더링 된 Gantt 차트 이미지에 표시되는 방식을 프로그래밍 방식으로 제어하여보고 및 시각적 분석을보다 의미있게 만듭니다.

맞춤형 바 스타일 정의

특정 작업 또는 작업 세트에 대한 새로운 스타일을 정의하려면 다음과 같습니다.

  1. ‘GanttbarStyle’의 새 인스턴스를 만듭니다.
  2. showfortaskuid,middleshape ',startshape’,endshape,`fillcolor ‘등과 같은 속성을 설정하십시오.
  3. 렌더링하기 전에 ‘imagesaveOptions.barstyles’컬렉션에 스타일을 추가하십시오.

Tip: The ShowForTaskUid property specifies which task UID this style applies to. You can also apply a style globally by omitting it.

예 : 특정 작업에 사용자 정의 스타일을 적용하십시오

 1static void ImplementCustomBarStyle()
 2{
 3    Project project = new Project("New Project.mpp");
 4    project.RootTask.Children.Add("Task");
 5
 6    GanttChartView view = project.DefaultView as GanttChartView;
 7    GanttBarStyle custom = GetCustomBarStyle();
 8
 9    // Add the custom bar style to the custom bar collection of the project view
10    view.CustomBarStyles.Add(custom);
11
12    MPPSaveOptions options = new MPPSaveOptions();
13    options.WriteViewData = true;
14
15    project.Save("ImplementCustomBarStyle_out.mpp", options);
16}
17
18static GanttBarStyle GetCustomBarStyle()
19{
20    GanttBarStyle style = new GanttBarStyle();
21    style.ShowFor = "1";
22    style.MiddleShape = GanttBarMiddleShape.RectangleBottom;
23    style.MiddleFillPattern = GanttBarFillPattern.MediumFill;
24    style.MiddleShapeColor = Color.Blue;
25
26    style.StartShape = GanttBarEndShape.ArrowDown;
27    style.StartShapeColor = Color.Red;
28
29    style.EndShape = GanttBarEndShape.ArrowUp;
30    style.EndShapeColor = Color.Yellow;
31
32    style.LeftField = Field.TaskResourceNames;
33    style.RightField = Field.TaskName;
34    style.TopField = Field.TaskStart;
35    style.BottomField = Field.TaskFinish;
36    style.InsideField = Field.TaskDuration;
37
38    return style;
39}

Reading Existing Custom Bar Styles

Aspose.Tasks also allows reading the GanttBarStyle objects from existing MPP files. This can be useful if you need to analyze or replicate the styling applied in Microsoft Project.

Example: Read All Custom Styles from a Project

 1Project project = new Project("New Project.mpp");
 2
 3GanttChartView view = project.DefaultView as GanttChartView;
 4Console.WriteLine("Custom bar styles count: {0}", view.CustomBarStyles.Count);
 5
 6GanttBarStyle style1 = view.CustomBarStyles[0];
 7
 8Console.WriteLine("Style1.LeftField is TaskDurationText : {0}", style1.LeftField.Equals(Field.TaskDurationText));
 9Console.WriteLine("Style1.RightField is TaskResourceNames : {0}", style1.RightField.Equals(Field.TaskResourceNames));
10Console.WriteLine("Style1.TopField is TaskACWP: {0}", style1.TopField.Equals(Field.TaskACWP));
11Console.WriteLine("Style1.BottomField is Undefined : {0}", style1.BottomField.Equals(Field.Undefined));
12Console.WriteLine("Style1.InsideField is Undefined : {0}", style1.InsideField.Equals(Field.Undefined));
13
14GanttBarStyle style2 = view.CustomBarStyles[1];
15Console.WriteLine("Style2.LeftField is TaskActualWork : {0}", style2.LeftField.Equals(Field.TaskActualWork));
16Console.WriteLine("Style2.RightField is TaskActualCost : {0}", style2.RightField.Equals(Field.TaskActualCost));
17Console.WriteLine("Style2.TopField is Undefined : {0}", style2.TopField.Equals(Field.Undefined));
18Console.WriteLine("Style2.BottomField is Undefined : {0}", style2.BottomField.Equals(Field.Undefined));
19Console.WriteLine("Style2.InsideField is Undefined : {0}", style2.InsideField.Equals(Field.Undefined));
20
21GanttBarStyle style3 = view.CustomBarStyles[2];
22Console.WriteLine("Style3.LeftField is TaskPercentComplete : {0}", style3.LeftField.Equals(Field.TaskPercentComplete));
23Console.WriteLine("Style3.RightField is TaskPercentWorkComplete : {0}", style3.RightField.Equals(Field.TaskPercentWorkComplete));
24Console.WriteLine("Style3.TopField is Field.TaskActive : {0}", style3.TopField.Equals(Field.TaskActive));
25Console.WriteLine("Style3.BottomField is TaskActualCost : {0}", style3.BottomField.Equals(Field.TaskActualCost));
26Console.WriteLine("Style3.InsideField is Field.TaskActualDuration : {0}", style3.InsideField.Equals(Field.TaskActualDuration));
27
28Console.WriteLine("Style3.StartShape is HouseDown : {0}", style3.StartShape.Equals(GanttBarEndShape.HouseDown));
29Console.WriteLine("Style3.StartShapeType is Framed : {0}", style3.StartShapeType.Equals(GanttBarType.Framed));
30Console.WriteLine("Style3.StartShapeColor is Red : {0}", style3.StartShapeColor.Equals(Color.FromArgb(Color.Red.ToArgb())));
31
32Console.WriteLine("Style3.EndShape is CircleDiamond : {0}", style3.EndShape.Equals(GanttBarEndShape.CircleDiamond));
33Console.WriteLine("Style3.EndShapeType is Solid : {0}",  style3.EndShapeType.Equals(GanttBarType.Solid) );
34Console.WriteLine("Style3.EndShapeColor is Yellow : {0}",  style3.EndShapeColor.Equals(Color.FromArgb(Color.Yellow.ToArgb())));
35
36Console.WriteLine("Style3.MiddleShape is RectangleTop : {0}", style3.MiddleShape.Equals(GanttBarMiddleShape.RectangleTop));
37Console.WriteLine("Style3.MiddleFillPattern is SolidFill : {0}", style3.MiddleFillPattern.Equals(GanttBarFillPattern.SolidFill));
38Console.WriteLine("Style3.EndShapeColor is Red : {0}", style3.MiddleShapeColor.Equals(Color.FromArgb(Color.Red.ToArgb())));

Common Use Cases

Custom bar styles are commonly used to:

Summary

Aspose.Tasks for .NET provides full control over how tasks are visualized in Gantt charts via the GanttBarStyle class. Whether you’re creating a new report or replicating Microsoft Project output, the API allows for precise control of shapes, colors, text labels, and styling logic.

Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.