Example of Flow Chart in ASP.NET MVC Diagram Control
This sample demonstrates a credit card order-processing workflow created using built-in flow shapes in the Lumen.UI Diagram. Drag a flow shape or a connector from the palette onto the diagram. Click a node to select it, drag it to move it (its connectors follow), drag a handle to resize or rotate it, double-click it to change its text. With the keyboard: Tab to a node, the arrow keys move it, F2 edits its text, Delete removes it.
@using System.Collections.Generic
@* The toolbar, the palette and the diagram work together by id: the TargetId of the first two and the Id of the diagram are the same. *@
@Html.UiDiagramToolbar(new UiDiagramToolbarOptions
{
TargetId = "flowChart",
Items = (List<UiDiagramToolbarItem>)ViewData["tbItems"],
ShapeStyle = new UiDiagramStyle { Fill = UiDiagramTemplates.FlowBlue, StrokeColor = "#ffffff", Color = "#ffffff" },
ConnectorStyle = new UiDiagramStyle { StrokeColor = "#000000" }
})
@Html.UiSymbolPalette((UiSymbolPaletteOptions)ViewData["palette"])
@Html.UiDiagram(new UiDiagramOptions
{
Id = "flowChart",
Height = "700px",
AriaLabel = "Credit card order flow chart",
SnapSettings = new UiDiagramSnapSettings { ShowGrid = true },
Nodes = (List<UiDiagramNode>)ViewData["nodes"],
Connectors = (List<UiDiagramConnector>)ViewData["connectors"]
})
@using System.Collections.Generic
@* The toolbar, the palette and the diagram work together by id: the TargetId of the first two and the Id of the diagram are the same. *@
<p>
This sample demonstrates a credit card order-processing workflow created using built-in flow shapes in the Lumen.UI Diagram.
Drag a flow shape or a connector from the palette onto the diagram. Click a node to select it, drag it to move it (its connectors
follow), drag a handle to resize or rotate it, double-click it to change its text. With the keyboard: <kbd>Tab</kbd> to a node,
the arrow keys move it, <kbd>F2</kbd> edits its text, <kbd>Delete</kbd> removes it.
</p>
@Html.UiDiagramToolbar(new UiDiagramToolbarOptions
{
TargetId = "flowChart",
Items = (List<UiDiagramToolbarItem>)ViewData["tbItems"],
ShapeStyle = new UiDiagramStyle { Fill = UiDiagramTemplates.FlowBlue, StrokeColor = "#ffffff", Color = "#ffffff" },
ConnectorStyle = new UiDiagramStyle { StrokeColor = "#000000" }
})
<div style="display:flex; gap:8px; align-items:flex-start">
@Html.UiSymbolPalette((UiSymbolPaletteOptions)ViewData["palette"])
<div style="flex:1; min-width:0">
@Html.UiDiagram(new UiDiagramOptions
{
Id = "flowChart",
Height = "700px",
AriaLabel = "Credit card order flow chart",
SnapSettings = new UiDiagramSnapSettings { ShowGrid = true },
Nodes = (List<UiDiagramNode>)ViewData["nodes"],
Connectors = (List<UiDiagramConnector>)ViewData["connectors"]
})
</div>
</div>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Lumen.UI.Mvc;
namespace YourApp.Controllers
{
public class DiagramController : Controller
{
// The page is Views/Diagram/FlowChart.cshtml; it draws what ViewData holds.
public ActionResult FlowChart()
{
var nodes = new List<UiDiagramNode>
{
UiDiagramTemplates.FlowNode("order", 340, 80, "Place Order", "Terminator"),
UiDiagramTemplates.FlowNode("start", 340, 160, "Start Transaction", "Process"),
UiDiagramTemplates.FlowNode("verify", 340, 240, "Verification", "Process"),
UiDiagramTemplates.FlowNode("valid", 340, 330, "Credit Card Valid?", "Decision"),
UiDiagramTemplates.FlowNode("payment", 550, 330, "Enter Payment Method", "Process"),
UiDiagramTemplates.FlowNode("funds", 340, 430, "Funds Available", "Decision"),
UiDiagramTemplates.FlowNode("complete", 340, 530, "Complete Transaction", "Process"),
UiDiagramTemplates.FlowNode("email", 120, 530, "Send E-mail", "Data"),
UiDiagramTemplates.FlowNode("database", 550, 530, "Customer Database", "DirectData"),
UiDiagramTemplates.FlowNode("log", 340, 630, "Log Transaction", "Terminator"),
UiDiagramTemplates.FlowNode("reconcile", 550, 630, "Reconcile the entries", "Process")
};
var connectors = new List<UiDiagramConnector>
{
UiDiagramTemplates.FlowLink("f1", "order", "start"),
UiDiagramTemplates.FlowLink("f2", "start", "verify"),
UiDiagramTemplates.FlowLink("f3", "verify", "valid"),
UiDiagramTemplates.FlowLink("f4", "valid", "payment", "No"),
UiDiagramTemplates.FlowLink("f5", "payment", "start"),
UiDiagramTemplates.FlowLink("f6", "valid", "funds", "Yes"),
UiDiagramTemplates.FlowLink("f7", "funds", "payment"),
UiDiagramTemplates.FlowLink("f8", "funds", "complete", "Yes"),
UiDiagramTemplates.FlowLink("f9", "complete", "email"),
UiDiagramTemplates.FlowLink("f10", "complete", "database"),
UiDiagramTemplates.FlowLink("f11", "complete", "log"),
UiDiagramTemplates.FlowLink("f12", "log", "reconcile", null, true)
};
ViewData["nodes"] = nodes;
ViewData["connectors"] = connectors;
ViewData["palette"] = UiDiagramTemplates.FlowShapesPalette("flowChart");
// The toolbar: each button by name with its tooltip; a button with a menu says what the menu lists (Value is what it does, Text what it says).
var exportItems = new List<UiDiagramToolbarMenuItem>
{
new UiDiagramToolbarMenuItem { Value = "JPG", Text = "JPG" },
new UiDiagramToolbarMenuItem { Value = "PNG", Text = "PNG" },
new UiDiagramToolbarMenuItem { Value = "SVG", Text = "SVG" }
};
var connectorItems = new List<UiDiagramToolbarMenuItem>
{
new UiDiagramToolbarMenuItem { Value = "Straight", Text = "Straight" },
new UiDiagramToolbarMenuItem { Value = "Orthogonal", Text = "Orthogonal" },
new UiDiagramToolbarMenuItem { Value = "Bezier", Text = "Bezier" }
};
var shapeItems = new List<UiDiagramToolbarMenuItem>
{
new UiDiagramToolbarMenuItem { Value = "Basic:Rectangle", Text = "Rectangle" },
new UiDiagramToolbarMenuItem { Value = "Basic:Ellipse", Text = "Ellipse" },
new UiDiagramToolbarMenuItem { Value = "Flow:Process", Text = "Process" },
new UiDiagramToolbarMenuItem { Value = "Flow:Decision", Text = "Decision" }
};
var alignItems = new List<UiDiagramToolbarMenuItem>
{
new UiDiagramToolbarMenuItem { Value = "Left", Text = "Align Left" },
new UiDiagramToolbarMenuItem { Value = "Center", Text = "Align Center" },
new UiDiagramToolbarMenuItem { Value = "Right", Text = "Align Right" },
new UiDiagramToolbarMenuItem { Value = "Top", Text = "Align Top" },
new UiDiagramToolbarMenuItem { Value = "Middle", Text = "Align Middle" },
new UiDiagramToolbarMenuItem { Value = "Bottom", Text = "Align Bottom" }
};
var distributeItems = new List<UiDiagramToolbarMenuItem>
{
new UiDiagramToolbarMenuItem { Value = "BottomToTop", Text = "Distribute Objects Vertically" },
new UiDiagramToolbarMenuItem { Value = "RightToLeft", Text = "Distribute Objects Horizontally" }
};
var orderItems = new List<UiDiagramToolbarMenuItem>
{
new UiDiagramToolbarMenuItem { Value = "moveForward", Text = "Bring Forward" },
new UiDiagramToolbarMenuItem { Value = "bringToFront", Text = "Bring To Front" },
new UiDiagramToolbarMenuItem { Value = "sendBackward", Text = "Send Backward" },
new UiDiagramToolbarMenuItem { Value = "sendToBack", Text = "Send To Back" },
new UiDiagramToolbarMenuItem { Value = "group", Text = "Group" },
new UiDiagramToolbarMenuItem { Value = "unGroup", Text = "Ungroup" }
};
var rotateItems = new List<UiDiagramToolbarMenuItem>
{
new UiDiagramToolbarMenuItem { Value = "90", Text = "Rotate Clockwise" },
new UiDiagramToolbarMenuItem { Value = "-90", Text = "Rotate Counter-Clockwise" }
};
var flipItems = new List<UiDiagramToolbarMenuItem>
{
new UiDiagramToolbarMenuItem { Value = "Horizontal", Text = "Flip Horizontal" },
new UiDiagramToolbarMenuItem { Value = "Vertical", Text = "Flip Vertical" }
};
var zoomItems = new List<UiDiagramToolbarMenuItem>
{
new UiDiagramToolbarMenuItem { Value = "in", Text = "Zoom In" },
new UiDiagramToolbarMenuItem { Value = "out", Text = "Zoom Out" },
new UiDiagramToolbarMenuItem { Value = "fit", Text = "Zoom to Fit" },
new UiDiagramToolbarMenuItem { Value = "0.5", Text = "Zoom to 50%" },
new UiDiagramToolbarMenuItem { Value = "1", Text = "Zoom to 100%" },
new UiDiagramToolbarMenuItem { Value = "2", Text = "Zoom to 200%" }
};
ViewData["tbItems"] = new List<UiDiagramToolbarItem>
{
new UiDiagramToolbarItem { Name = "new", Tooltip = "New Diagram" },
new UiDiagramToolbarItem { Name = "open", Tooltip = "Open Diagram" },
new UiDiagramToolbarItem { Name = "save", Tooltip = "Save Diagram" },
new UiDiagramToolbarItem { Name = "print", Tooltip = "Print Diagram" },
new UiDiagramToolbarItem { Name = "export", Tooltip = "Export Diagram", Menu = exportItems },
UiDiagramToolbarItem.Separator,
new UiDiagramToolbarItem { Name = "cut", Tooltip = "Cut" },
new UiDiagramToolbarItem { Name = "copy", Tooltip = "Copy" },
new UiDiagramToolbarItem { Name = "paste", Tooltip = "Paste" },
UiDiagramToolbarItem.Separator,
new UiDiagramToolbarItem { Name = "undo", Tooltip = "Undo" },
new UiDiagramToolbarItem { Name = "redo", Tooltip = "Redo" },
UiDiagramToolbarItem.Separator,
new UiDiagramToolbarItem { Name = "pan", Tooltip = "Pan Tool" },
new UiDiagramToolbarItem { Name = "select", Tooltip = "Select Tool" },
new UiDiagramToolbarItem { Name = "connector", Tooltip = "Draw Connectors", Menu = connectorItems },
new UiDiagramToolbarItem { Name = "shape", Tooltip = "Draw Shapes", Menu = shapeItems },
new UiDiagramToolbarItem { Name = "text", Tooltip = "Text Tool" },
UiDiagramToolbarItem.Separator,
new UiDiagramToolbarItem { Name = "lock", Tooltip = "Lock" },
new UiDiagramToolbarItem { Name = "delete", Tooltip = "Delete" },
UiDiagramToolbarItem.Separator,
new UiDiagramToolbarItem { Name = "align", Tooltip = "Align Objects", Menu = alignItems },
new UiDiagramToolbarItem { Name = "distribute", Tooltip = "Distribute Objects", Menu = distributeItems },
UiDiagramToolbarItem.Separator,
new UiDiagramToolbarItem { Name = "order", Tooltip = "Order Commands", Menu = orderItems },
UiDiagramToolbarItem.Separator,
new UiDiagramToolbarItem { Name = "selection", Tooltip = "Select Objects" },
UiDiagramToolbarItem.Separator,
new UiDiagramToolbarItem { Name = "rotate", Tooltip = "Rotate", Menu = rotateItems },
UiDiagramToolbarItem.Separator,
new UiDiagramToolbarItem { Name = "flip", Tooltip = "Flip", Menu = flipItems },
UiDiagramToolbarItem.Separator,
new UiDiagramToolbarItem { Name = "zoom", Tooltip = "Zoom", Menu = zoomItems }
};
return View();
}
}
}
@* Install once: Install-Package Lumen.UI.Mvc (or: dotnet add package Lumen.UI.Mvc) *@
@* Views/Web.config: <add namespace="Lumen.UI.Mvc" /> *@
@* Views/Shared/_Layout.cshtml *@
<head>
@Html.UiStyles()
<link rel="stylesheet" href="~/Content/site.css" />
</head>
<body>
@RenderBody()
@Html.UiScripts()
@RenderSection("scripts", required: false)
</body>