I managed to render the organization from my employee table by referencing documentation, but I'm facing three major issues:
I'm currently using Net9 with Version="28.1.36".
Below is my current code.
@page "/organizationchart" @rendermode InteractiveServer @using Syncfusion.Blazor.Diagram @using Microsoft.EntityFrameworkCore @using SyncfusionBlazorApp1.Data @inject ApplicationDbContext DbContext <SfDiagramComponent Height="600px" NodeCreating="@OnNodeCreating" ConnectorCreating="@OnConnectorCreating"> <DataSourceSettings ID="id" ParentID="manager" DataSource="@DataSource"></DataSourceSettings> <Layout Type="LayoutType.OrganizationalChart" @bind-HorizontalSpacing="@HorizontalSpacing" @bind-VerticalSpacing="@VerticalSpacing"> </Layout> </SfDiagramComponent> @code { int HorizontalSpacing = 40; int VerticalSpacing = 50; public List<OrgChartNode> DataSource = new(); protected override void OnInitialized() { try { DataSource.Clear(); // 1. 부서 데이터 로드 - ToList() 사용 var departments = DbContext.Departments.ToList(); foreach (var dept in departments) { DataSource.Add(new OrgChartNode { id = $"D{dept.Id}", text = dept.Name, manager = null, isDepartment = true }); } // 2. 직원 데이터 로드 - ToList() 사용 var employees = DbContext.Employees .Include(e => e.Position) .Include(e => e.Department) .ToList(); foreach (var emp in employees) { DataSource.Add(new OrgChartNode { id = emp.Id.ToString(), text = $"{emp.Name}\n{emp.Position.Name}", manager = $"D{emp.DepartmentId}", isDepartment = false }); } } catch (Exception ex) { Console.WriteLine($"Error loading data: {ex.Message}"); } } private void OnNodeCreating(IDiagramObject obj) { Node node = obj as Node; OrgChartNode data = node.Data as OrgChartNode; if (data.isDepartment) { // 부서 노드 스타일 node.Height = 70; node.Width = 200; node.Style = new ShapeStyle() { Fill = "#357BD2", StrokeWidth = 2, StrokeColor = "Black" }; } else { // 직원 노드 스타일 node.Height = 60; node.Width = 150; node.Style = new ShapeStyle() { Fill = "#6BA5D7", StrokeWidth = 1, StrokeColor = "Black" }; } node.Annotations = new DiagramObjectCollection<ShapeAnnotation>() { new ShapeAnnotation() { Content = data.text, Style = new TextStyle() { Color = "white", Fill = "transparent" } } }; } private void OnConnectorCreating(IDiagramObject connector) { Connector connectors = connector as Connector; connectors.Type = ConnectorSegmentType.Orthogonal; connectors.Style = new TextStyle() { StrokeColor = "#6495ED", StrokeWidth = 1 }; connectors.TargetDecorator = new DecoratorSettings { Shape = DecoratorShape.None, Style = new ShapeStyle() { Fill = "#6495ED", StrokeColor = "#6495ED" } }; } public class OrgChartNode { public string id { get; set; } public string manager { get; set; } public string text { get; set; } public bool isDepartment { get; set; } } } |
Hi Lee,
We tried reproducing the behavior on our end and encountered a similar issue. To assist further, we’ve attached our working sample for your reference.
Could you please confirm if this matches the issue you’re experiencing? If there’s anything missing in the sample, kindly make the necessary changes and provide detailed replication steps. This will help us investigate and provide a solution promptly.
We appreciate your cooperation and look forward to your response.
Best regards,
Bala Vignesh R
Thx Balavignesh RaviChandran,
But
Hi Lee,
To clarify, the sample we shared earlier was intended to confirm whether we correctly understood the issues you are experiencing. We aimed to replicate the behavior based on your description.
Could you kindly elaborate further on the following points to help us investigate and provide an effective solution?
OnInitializedAsync. If your scenario differs or requires additional changes, please provide a working sample replicating the issue or make changes to the shared sample and share it with us.Please confirm whether your issue aligns with our findings or share further details so we can assist you better.