Creating Custom Graphs with Spira (Part 1)

October 23rd, 2019 by inflectra

One of the maxims I always tell developers is that regardless of what you build, customers will never be satisfied with the reports you offer or the integration that you provide. In fact, the two most underestimated tasks in software development are data feeds and reporting. So one of the nice features in our Spira platform is the ability to do custom graphing, so that you are not limited to just the graphs that ship with the system. This article is the first in a series that explains how to use these powerful custom graphing features, which continues on from our previous series on custom reporting!

Creating Custom Graphs

To create a custom report, simply go to the new Edit Graphs option in the Reporting section of the Administration module:

When you click on the Edit Graphs link, you will be taken to the custom graph configuration page where you can add / modify custom graphs.

This page lets you create custom graphs and charts in the system that your users can run in the various products they have access to. Note that the graph definitions themselves are global to the system and therefore available in all products.

You can click on the Edit button to modify an existing graph, or click on the Add New Custom Graph option to create an entirely new one. In either case, you will see the custom graph editing screen.

In addition, the graph list page has the following additional operations:

  • Clone -- this will make a copy of the graph with '- Copy' appended to the name

  • Delete -- this will permanently delete the selected custom graph.


On the graph editing page, you can enter the following fields:

  • Name -- This is the short name of the graph that will be displayed to users when they choose to display a custom graph.

  • Description -- This is the longer description of the graph, and should be used to explain what the data in the graph shows, what the purpose of the graph is and how the data should be interpreted. This is what the user will see when they click on the help link on the graph.

  • Active -- If you set this to "No", the graph will not be accessible by end users

  • Position -- use this to specify the relative position of the graph in the list of custom graphs.

  • Query -- this is where you enter the actual query used to generate the graph data. We shall discuss this below.

Writing the ESQL Query Used in the Graph

The Query box is where you can choose the Reportable Entity from the dropdown list and then use that base query to create your own custom query.

We recommend that you first choose the appropriate reportable entity from the dropdown list. In the example illustrated below, we have selected the "Test Runs" reportable entity:

This will automatically populate the following query in the Query editor:

select value R from SpiraTestEntities.R_TestRuns as R where R.PROJECT_ID = ${ProjectId}

This query tells Spira to select all of the rows in the R_TestRuns collection that are in the current product and include all of the columns in the final report. You cannot graph non-numeric columns, so usually we'd recommend clicking Display Data Grid to see all of the columns that you can use in the graph:

This will help you decide which columns are important for your graph. You can then adjust the query to only include those columns:

from SpiraTestEntities.R_TestRuns as R
where R.PROJECT_ID = ${ProjectId}

In this modified query, we have replaced the keyword value with the specific column names. We have also added an aggregation function called COUNT to count the number of test runs and group by the execution status name column. Spira uses a modified SQL language called Entity SQL created by Microsoft that we'll be discussing in more detail in later articles in this series.

You may have noticed that we had a special token in the query ${ProjectId}, this token will be evaluated during the generation of the graph and ensures that only items in the current product are included. If you want to include all the items in a specific Program, you should instead use the token ${ProjectGroupId}. If you don't use either token, the graph will include all the items in the entire system, across all products and programs.

There are some restrictions about the select clause of the query:

  • You need to make the first column in the query the category for the x-axis
  • The other columns need to be purely numeric, and will be used to populate the data series that will be mapped to the x-axis categories.

You can test out your modified query by clicking the Display Data Grid button again. For our example test runs query above the system will now display:

Then once you have verified the data makes sense, click on the three different Preview Graph buttons to see how the data will look as a donut, bar, or  line graph.

Note: For donut graphs, only one data range is supported, for line/bar charts, you can have multiple ranges.

a) Donut Chart

b) Bar Graph

c) Line Chart


Once you are happy with your graph design, make sure the Active flag is set to Yes and then click Save to publish the graph for your end users.

Warning: If you create a graph that doesn't have either ${ProjectId} or ${ProjectGroupId} in the WHERE clause you could end up displaying data to a user that shouldn't have permission to see that data.

Viewing Custom Graphs

Once published, the custom graphs can be displayed in the main Reports dashboard by your end users:

Once you have added an instance of the Custom Graphs to your dashboard, you can choose the specific graph, and the visualization type (donut, bar, and line currently):

You can display the data being used to generate the graph by clicking on the data-grid button in the bottom-left:


As with all of the graphs on the reporting dashboard, you can export the data-grid as a CSV / Excel sheet, and export the actual graph as an image (PNG, JPEG, and BMP formats supported).

Delving Deeper into Entity SQL (ESQL)

Now that we have seen how the Spira custom graphing system works, our next article in this series will explain how you can use Entity SQL to write queries to pull back the data you need for your graphs.

custom reporting custom graphs spira

Spira Helps You Deliver Better Software, Faster.

Get Started with Spira for Free

And if you have any questions, please email or call us at +1 (202) 558-6885

Free Trial