カスタムバースタイルを使用します
概要
Microsoft Projectでは、Ganttチャートビューでは、ユーザーはカスタムバースタイルを定義して視覚化を改善したり、特定のタイプのタスクを強調したりできます。これには、バーの外観(スタート、ミドル、エンド)の変更、カスタムカラーの追加、シェイプの調整、およびタスクバーの上にテキストラベルの構成が含まれます。
.NETのAspose.Tasksは、 ganttbarstyle
クラスを介してこのレベルのカスタマイズをサポートしています。これにより、開発者は、各タスク(またはタスクのグループ)がレンダリングされたガントチャート画像に表示される方法をプログラム的に制御でき、レポートと視覚分析をより意味のあるものにします。
カスタムバースタイルの定義
特定のタスクまたは一連のタスクの新しいスタイルを定義するには、次のことが必要です。
- 「ganttbarstyle」の新しいインスタンスを作成します。
- 「showfortaskuid」、「middlesshape」、「startshape」、「endshape」、「fillcolor」などのプロパティを設定します。
- レンダリングの前に「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())));
一般的なユースケース
カスタムバースタイルは、主に以下の目的で使用されます。
- マイルストーン、クリティカルタスク、またはサマリータスクを視覚的に区別する。
- チームや部門ごとに色分けを適用する。
- カスタムフィールド (
Text1
、ResourceNames
など) に基づいて、タスクに動的にラベルを付ける。 - 遅延タスク を独自の色や図形で強調表示する。
概要
Aspose.Tasks for .NET は、GanttBarStyle
クラスを使用して、ガントチャートにおけるタスクの表示方法を完全に制御できます。新しいレポートを作成する場合でも、Microsoft Project の出力を複製する場合でも、API を使用することで、図形、色、テキストラベル、スタイル設定ロジックを詳細に制御できます。