이 튜토리얼에서는 C#에서 ORG 차트를 만드는 방법에 대해 설명합니다. C#으로 조직 차트 작성기를 개발하기 위한 시스템 구성 단계별 절차와 코드 조각에 대해 설명합니다. 또한 이 코드 조각은 요구 사항에 따라 ORG chart을 생성하도록 향상될 수 있습니다.
C#에서 ORG 차트를 만드는 단계
- ORG 차트를 생성하려면 시스템에서 Aspose.Diagram API를 구성하세요.
- Diagram 클래스를 사용하여 기존 스텐실에서 마스터 셰이프를 로드합니다.
- 새 모양을 추가하고 노드 간 연결 만들기
- LayoutOptions 클래스를 사용하여 차트 속성을 설정하고 출력 ORG 차트 다이어그램을 저장합니다.
이 단계에서는 C#*에서 *ORG 차트 생성기를 만드는 알고리즘을 다룹니다. 전제 조건으로 환경을 구성하고 기존 스텐실에서 마스터 셰이프를 로드합니다. 그런 다음 출력 다이어그램 파일을 저장하기 전에 모양과 해당 연결을 추가합니다.
C#에서 ORG 차트를 만드는 코드
using System; | |
using System.Collections.Generic; | |
class Program | |
{ | |
static void Main(string[] args) // Create organization chart in C# | |
{ | |
// Set the license | |
new Aspose.Diagram.License().SetLicense("License.lic"); | |
// Load the masters | |
string visioStencil = "BasicShapes.vss"; | |
const string rectangleMaster = "Rectangle"; | |
const string connectorMaster = "Dynamic connector"; | |
const int pageNumber = 0; | |
const double width = 1; | |
const double height = 1; | |
double pinX = 4.25; | |
double pinY = 9.5; | |
// Define the hierarchy | |
List listPos = new List(new string[] { "0", "0:0", "0:1", "0:2", "0:3", "0:4", "0:5", "0:6", "0:0:0", "0:0:1", "0:3:0", "0:3:1", "0:3:2", "0:6:0", "0:6:1" }); | |
// Define a Hashtable for name and shape id | |
System.Collections.Hashtable shapeIdMap = new System.Collections.Hashtable(); | |
// Create a new diagram | |
Aspose.Diagram.Diagram diagram = new Aspose.Diagram.Diagram(visioStencil); | |
diagram.Pages[pageNumber].PageSheet.PageProps.PageWidth.Value = 11; | |
foreach (string orgnode in listPos) | |
{ | |
// Add a new rectangle shape | |
long rectangleId = diagram.AddShape(pinX++, pinY++, width, height, rectangleMaster, pageNumber); | |
// Set the new shape's properties | |
Aspose.Diagram.Shape shape = diagram.Pages[pageNumber].Shapes.GetShape(rectangleId); | |
shape.Text.Value.Add(new Aspose.Diagram.Txt(orgnode)); | |
shape.Name = orgnode; | |
shapeIdMap.Add(orgnode, rectangleId); | |
} | |
// Create connections between nodes | |
foreach (string orgName in listPos) | |
{ | |
int lastColon = orgName.LastIndexOf(':'); | |
if (lastColon > 0) | |
{ | |
string parendName = orgName.Substring(0, lastColon); | |
long shapeId = (long)shapeIdMap[orgName]; | |
long parentId = (long)shapeIdMap[parendName]; | |
Aspose.Diagram.Shape connector1 = new Aspose.Diagram.Shape(); | |
long connecter1Id = diagram.AddShape(connector1, connectorMaster, pageNumber); | |
diagram.Pages[pageNumber].ConnectShapesViaConnector(parentId, Aspose.Diagram.Manipulation.ConnectionPointPlace.Right, | |
shapeId, Aspose.Diagram.Manipulation.ConnectionPointPlace.Left, connecter1Id); | |
} | |
} | |
//auto layout CompactTree chart | |
Aspose.Diagram.AutoLayout.LayoutOptions compactTreeOptions = new Aspose.Diagram.AutoLayout.LayoutOptions | |
{ | |
LayoutStyle = Aspose.Diagram.AutoLayout.LayoutStyle.CompactTree, | |
Direction = Aspose.Diagram.AutoLayout.LayoutDirection.DownThenRight, | |
EnlargePage = false | |
}; | |
diagram.Pages[pageNumber].Layout(compactTreeOptions); | |
// Save diagram | |
diagram.Save("ORGChart_out.vsdx", Aspose.Diagram.SaveFileFormat.Vsdx); | |
Console.WriteLine("Done"); | |
} | |
} | |
이 코드 조각은 C#*에서 *ORG 차트 빌더를 만들기 위해 설계되었습니다. 그러나 AddShape 메서드에서 직사각형 모양의 수, 높이, 너비, 위치 등을 변경하는 등 필요에 맞게 수정할 수 있습니다. 마찬가지로 요구 사항에 맞게 상위 모양 ID 또는 연결 지점을 사용하여 노드 간의 연결을 조작할 수 있습니다.
이 기본 튜토리얼에서는 C#*에서 *ORG 차트 작성기 작성에 대한 세부사항을 다루었습니다. 반면, 순서도를 그리려면 C#에서 순서도를 만드는 방법의 기사를 읽어보세요.