Creating Charts from your Graphs
By: Adam Cowley
Tags: Neo4j, Data Visualization, Charts, Dashboard, Data Analysis

Over the past few years I’ve spent a lot of time trying to define the difference between a Graph and a Chart. But I’m here today to muddy the waters once again.

I’d like to introduce a Graph App that I’ve been working on for the past few weeks, simply called Charts. I’ve designed the app to be useful to both beginners to Neo4j or more experienced users who would like to make their graph-shaped data more understandable to the people around them.

As the name suggests, Charts allows you to create sets of charts from the data held in a Neo4j Database. The Graph App will take the raw results from a Cypher query and convert them into the correct format for the applicable chart, meaning you only have to do a minimal amount of manipulation to the data within your query.

For example, the Metric report will take the first value of the first row and display it in on screen, treating it as a number.

The range of Bar reports (either horizontal or vertical orientation, and stacked or unstacked) all require a set of results with a key , x value and y value and are converted into the correct format by the underlying React component.

Visual Query Builder

For those that aren’t so familiar with the Cypher query language, or those that aren’t interested in writing code at all, the app includes a Visual Query Builder. The query builder inspects your graph structure and provides links to build up a graph pattern without writing a line of code.

After selecting the starting label for the pattern (eg. Person or Movie), the right hand panel will display a list of relationships going into or out of that label. You can continue to click through the graph pattern until you have built up your pattern.

As you build the query, the raw Cypher query will show up in the bottom left hand corner of the screen. You can copy and paste this into Neo4j Browser to preview the results as you go.

Once you have built up the graph pattern, you can click the Where Tab on the right hand panel to add predicates to your where clause. You can select from a range of conditions including equals, starts with, ends with, greater than or less than, and if it’s a negative predicate, tick the NOT checkbox.

As you add these, a set of :param statements will be appended to the top of the query — you should copy these one by one into Neo4j Browser before running your query.

After you have built up the query, you can use the Return Tab to select which properties you would like to return. You can provide an alias to the field and also select from a number of aggregate functions including sum(), count(), and collect().

You’ll end up with a generated cypher query similar to the following:

MATCH (n1:Actor)-[r1:ACTED_IN]->(n2:Movie)-[r2:IN_GENRE]->(n3:Genre)

WHERE (n1.name = $n1_name AND NOT r1.role = $r1_role)

RETURN n2.title AS title, collect(n3.name)

Dashboards

Dashboards are a way of grouping and displaying data. You can create as many dashboards as you need to group different pieces of information together.

You can click Add Dashboard to create a new Dashboard, then click the Add Report button in the top right hand corner to start adding data to the dashboard.

Each dashboard can then contain a number of Reports. Reports use the current Neo4j Connection to return data in a number of formats — signified by the report Type. These can range from simple displays like a Metric (a single figure) or a Table of results to more complex Chart types including Line, Bar and Radar charts.

The Source of each report can either be a Raw Cypher Query that you type directly into the box, or a Query that has been built in the query builder.

If the should be run on any database other than the default database (either the default as configured in neo4j.conf or as specified at login), you can define this in the Database field. You can also choose how many columns (between 1 and 4) the report spans visually in the dashboard.

Help Tab

If you get stuck at any point, you can click the Help link in the top right hand corner of the screen. This page provides a list of the available chart types and an example cypher query for populating the chart.