Here we show an example of creating a report for seeing the count of issues in every project, grouped by issue type.

 It is important to mention that the project and issue type grouping can be easily changed by introducing parameters.


What the report generates can be seen in the following image (without the axes, which were added only for better understanding):

  • on the horizontal axis (X), the groups are the projects
  • on the vertical axis (Y), the groups are the count of issues with a certain issue type

approve Download Scripted Chart Bundle

Chart preview

Parameters

ParameterTypeDefault value
Jql_ParamJQL autocomplete
GroupBy_PickerGroup By PickerProject
Layout Script

Used layout: Default Table.

var div = $("#chart");
var table = d3.select(div.parent().get(0)).append('table')
var thead = table.append('thead')
var tbody = table.append('tbody');
 
$("#chart ~ table").addClass("table")
thead.append('tr').selectAll('th').data(chartData.columns[1]).enter().append('th')
                  .text(function(column) { return column; });
$('thead > tr > th:first').text(chartData.ytype + " \\ " + chartData.xtype)
 
var tr = tbody.selectAll('tr').data(chartData.groups[0]).enter().append("tr");
 
var td = tr.selectAll("td").data(function(d) {
    var result = new Array();
    $.each(chartData.columns, function(index, value) {
        if (value[0] == d) {
            result.push.apply(result, value);
        }
    });
    return result;
}).enter().append("td").text(function(d, i) {
    return d;
});
Data Script
import java.lang.reflect.Field;
import java.math.BigDecimal;
import java.text.DateFormat;
  
import org.apache.lucene.document.Document;
  
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.DocumentIssueImpl;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.jql.parser.JqlQueryParser;
import com.atlassian.jira.user.ApplicationUser;
import com.atlassian.query.Query;
  
import com.decadis.jira.xchart.api.model.Period;
import com.decadis.jira.xchart.api.util.DateUtils;
import com.decadis.jira.xchart.api.model.ChartData;
  
DateFormat dateFormat = DateUtils.SimpleDateFormat;
   
JqlQueryParser jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser.class);
Query query = jqlQueryParser.parseQuery(Jql_Param); //this is the parameter we created
    
Period selectedPeriod = Period.MONTH;
def countGroup = chartBuilder.newDataCollector();
  
def groupValueExtractorX = chartBuilder.getGrouper(GroupBy_Picker); //must be a fieldid, so either Group By Picker, or hardcoded fieldid
def groupValueExtractorY = chartBuilder.getGrouper("issuetype"); //can be replaced by a parameter
  
Field documentField;
documentField = DocumentIssueImpl.class.getDeclaredField("document");
documentField.setAccessible(true);
   
for ( Issue issue : chartBuilder.getFilterUtils().performSearch(query, user) )
{
  for ( String groupX : groupValueExtractorX.getGroups((Document) documentField.get(issue)) )
  {
    for ( String groupY : groupValueExtractorY.getGroups((Document) documentField.get(issue)) )
    {
      groupY = (groupY != null) ? groupValueExtractorY.getResolvedValue(groupY, issue) : groupY;
      groupX = (groupX != null) ? groupValueExtractorX.getResolvedValue(groupX, issue) : groupX;
      countGroup.addValue(BigDecimal.ONE, groupY, groupX);
    }
  }
}
   
countGroup.fillMissingValues();
  
ChartData chartData = chartBuilder.newChartData("issuetype");
chartData.setXType("project");
chartData.setType("table");
  
chartBuilder.getChartUtil().transformResult(countGroup, chartData, true);
  
return chartData;



If you still have questions, feel free to refer to our support team.