Graph

Neo4j dashboard graphs render returned nodes, relationships and paths. Configure the graph layout and nodes, relationships, labels and colors to your liking.

You can drag and drop nodes in the displayed graph.

Cypher example

Cypher query for a graph which displays products which are part of the "produce" category
MATCH (p:Product)-[o:PART_OF]->(c:Category)
WHERE c.categoryName = "Produce"
RETURN p, o, c
visualization graph
Figure 1. A graph displaying the products which are part of the "produce" category

Configuration

Layout

Neo4j dashboard graphs have two layout options:

  1. Force-based layout, which spreads nodes evenly.

  2. Hierarchical layout, which respects the direction of relationships. Select one of: left to right, right to left, top to bottom, bottom to top.

Rule-based styling for graphs

Use rule-based styling to change the appearance of nodes and relationships.

Style all matching nodes or relationships by selecting a label or relationship type. Or, use a property and condition to style only a matching subset.

To add a rule, open the graph visualization’s Styling settings:

  • Select the Nodes or Relationships tab.

  • Select Add.

  • For nodes choose the label, and for relationships choose the type, then configure the rules.

  • (Optional) Select a property and condition to apply the rule only to matching nodes or relationships.

  • The first time you create a rule, Apply is selected by default.

  • Select Add to add the rule.

  • If you change the rule later, select Apply before selecting Add to apply the updated rule. To add the updated rule without applying it, select Add only.

  • Select Save on the card to save your changes.

When multiple rules match the same node or relationship, the rules are evaluated from top to bottom. Drag rules to change their order.

The available conditions depend on the property type that is selected:

Numeric properties
  • equals

  • does not equal

  • greater than

  • less than

  • greater than or equal to

  • less than or equal to

  • between

  • not between

  • is null

  • is not null

Text properties
  • contains

  • equals

  • does not equal

  • starts with

  • ends with

  • is null

  • is not null

Boolean properties
  • is true

  • is false

  • is null

  • is not null

Temporal properties
  • equals

  • does not equal

  • between

  • not between

  • before

  • after

  • is null

  • is not null

Most examples on this page use the Northwind dataset. The arc examples use virtual nodes and relationships generated by the query. They do not use Northwind data.

Style nodes

Use rules to change a node’s color, size or caption.

Highlight products by stock level

Set a base color

The following query returns suppliers and the products they supply:

Northwind supplier and product graph
MATCH (s:Supplier)-[r:SUPPLIES]->(p:Product)
RETURN s, r, p

Create a base style for all Product nodes.

Select the label Product and leave Property and Condition empty, select Color, and choose a single red color.

red product nodes
Figure 2. Red product nodes

Color nodes by condition

Create a rule for Product nodes to color products with more than 10 units in stock black.

Select the unitsInStock property, set the condition to greater than, enter 10, and set the color to black.

black product nodes
Figure 3. Black product nodes

Group suppliers by country

Color nodes by unique value

Use Unique value to assign a different color to each distinct value of a property. Nodes with the same value use the same automatically assigned color. The 33 colors in the palette repeat across nodes with unique values.

The following query returns suppliers in the USA, Germany, and UK, together with the products they supply:

Northwind suppliers and products in USA, Germany, UK
MATCH (s:Supplier)-[r:SUPPLIES]->(p:Product)
WHERE s.country IN ['USA', 'Germany', 'UK']
RETURN s, r, p

In this example, the rule uses the country property on Supplier nodes:

  • Suppliers in the USA are dark purple.

  • Suppliers in Germany are orange.

  • Suppliers in the UK are yellow.

graph unique value
Figure 4. Unique values for supplier countries

Use unique values when you want to distinguish categories, rather than show a value from low to high.

Show values with range

Color nodes by range

This Cypher example generates virtual nodes and relationships with a range of property types. It does not use Northwind data.

Generated arc as a sample graph for exploring rule-based styling
UNWIND range(10, 1, -1) AS i
WITH
  i,
  apoc.create.vNode(
    ['SampleNode'],
    {
      id: i,
      label: 'test' + i,
      intProp: i * 10,
      floatProp: i * 1.5,
      stringProp: 'Node_' + toString(i),
      boolProp: i % 2 = 0,
      point2dProp: point({x: i * 1.0, y: i * 2.0})
    }
  ) AS n
WITH collect({i: i, node: n}) AS nodes
UNWIND range(0, size(nodes) - 2) AS idx
WITH
  nodes,
  idx,
  nodes[idx].node AS startNode,
  nodes[idx + 1].node AS endNode,
  idx + 1 AS relIndex
RETURN
  endNode AS from,
  apoc.create.vRelationship(
    endNode,
    'CONNECTS_TO',
    {
      id: relIndex,
      weight: relIndex * 0.5,
      label: 'Edge_' + toString(relIndex),
      active: relIndex % 2 = 0,
      locationProp: point({x: relIndex * 1.0, y: relIndex * 2.0})
    },
    startNode
  ) AS rel,
  startNode AS to
ORDER BY relIndex;

For numeric properties, use Range to show values on a continuous scale.

In this example, nodes with IDs from 1 to 10 use a color range: green for the minimum value and red for the maximum value.

The minimum and maximum values are automatically set from the query results. You could also add a midpoint color to create a three-color range.

red to green arc
Figure 5. Green-to-red color range

Size nodes by range

You can also use a size range to make nodes with higher numeric values appear larger. For example, on the Size tab, select Range. The minimum and maximum values are automatically set from the id values 1 and 10.

Set their sizes to 0.25x and 5x. Nodes with IDs between these values are sized proportionally.

size red to green arc
Figure 6. Node size range

Style relationships

Highlight discounted orders

Color relationships by condition

Northwind order and product graph
MATCH (o:Order)-[ordered:ORDERS]->(p:Product)
RETURN o, ordered, p
LIMIT 10

On the Relationships tab, create a rule for ORDERS relationships. Select the discount property, set the condition to does not equal with a value of 0, then set the relationship color to red.

graph orders relationship
Figure 7. Orders with discounts shown as red arrows

Show order quantities

Add relationship captions

Set a relationship caption to display a property value on the arrow.

The following query returns orders and the products they contain:

Northwind orders and the products they contain
MATCH (o:Order)-[ordered:ORDERS]->(p:Product)
RETURN o, ordered, p
LIMIT 10

Add a rule for the ORDERS relationship type and set a relationship color. On the Caption tab, select quantity to show the number of units ordered on each arrow.

captions
Figure 8. Order quantities shown on relationships