How to Create Polygon and Circle Shapes in Syncfusion Blazor Diagram
Syncfusion Blazor Diagram provides options to create custom shapes like polygons and circles. This guide demonstrates how to use the Shape property to create and display these shapes in a Blazor diagram.
Steps:
- Define a Polygon Shape: Configure points to create a polygon using NodeBasicShapes.Polygon.
- Define a Circle Shape: Set up a node with NodeBasicShapes.Ellipse for a circular shape.
<SfDiagramComponent @ref="@diagram" Height="500px" Nodes="@nodes" />
@code {
SfDiagramComponent diagram;
DiagramObjectCollection<Node> nodes = new DiagramObjectCollection<Node>();
protected override void OnInitialized() {
Node polygonNode = new Node() {
ID = "polygonNode",
OffsetX = 500,
OffsetY = 200,
Style = new ShapeStyle() { Fill = "#6495ED" },
Shape = new BasicShape() {
Type = NodeShapes.Basic,
Points = new DiagramPoint[] {
new DiagramPoint() { X = 35 },
new DiagramPoint() { X = 65 },
new DiagramPoint() { X = 100, Y = 35 },
new DiagramPoint() { X = 100, Y = 65 },
new DiagramPoint() { X = 65, Y = 100 },
new DiagramPoint() { X = 35, Y = 100 },
new DiagramPoint() { Y = 65 },
new DiagramPoint() { Y = 35 }
},
Shape = NodeBasicShapes.Polygon
}
};
Node circleNode = new Node() {
ID = "circleNode",
OffsetX = 600,
OffsetY = 100,
Height = 100,
Width = 100,
Style = new ShapeStyle() { Fill = "yellow", StrokeWidth = 3, StrokeColor = "Black" },
Shape = new BasicShape() {
Type = NodeShapes.Basic,
Shape = NodeBasicShapes.Ellipse
}
};
nodes.Add(polygonNode);
nodes.Add(circleNode);
}
}
Result:
This code creates a polygon and a circle, both displayed on the diagram with customizable properties.
You can download the complete working sample from here.
Conclusion:
I hope you enjoyed how to Create a GroupNode
You can refer to our Blazor Diagram feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our Blazor Diagram example to understand how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, support portal, or feedback portal. We are always happy to assist you!
Related Resource
Shape Property
Node Customization