# Palette and Legend

## Content

**FlexDiagram** includes a built-in legend system that categorizes and visually distinguishes nodes. This system uses the <span class="code" spellcheck="false" data-prosemirror-content-type="mark" data-prosemirror-mark-name="code">LegendItem</span> property.

#### **How LegendItem Property Works**

1. **Automatic Node Coloring**
    Nodes that share the same LegendItem value receive the same color, selected sequentially from the diagram’s palette.
2. **Legend Generation**
    Each distinct LegendItem value appears as an entry in the diagram legend, making categories easy to understand.

#### **Using Custom Palettes**

FlexDiagram provides several built-in palettes. You can also assign custom palettes through the <span class="code" spellcheck="false" data-prosemirror-content-type="mark" data-prosemirror-mark-name="code">Palette</span> property.

#### **Add LegendItem Example**

Assign **LegendItem** property to group nodes into categories and display them in the diagram legend using the following code:

```auto
var node1 = new Node() { Text = "Node 1", LegendItem = "Group 1" };
var node2 = new Node() { Text = "Node 2", LegendItem = "Group 1" };
var node3 = new Node() { Text = "Node 3", LegendItem = "Group 2" };
var node4 = new Node() { Text = "Node 4", LegendItem = "Group 2" };

diagram.Nodes.Add(node1);
diagram.Nodes.Add(node2);
diagram.Nodes.Add(node3);
diagram.Nodes.Add(node4);
```

![](https://cdn.mescius.io/document-site-files/images/ba3667c3-8434-4d44-931a-224dda3ad70f/palette%20and%20legend%20for%20flexdiagram.233d9d.png)