Incident backlog rendering script

The incident backlog rendering script and an explanation of the script.

    //
    // Script generates a trending chart of open incidents and combines that with a
    // trending chart of the closed incidents and then above that
    // places a line that shows the backlog of incidents in the same time period.
    //
    // Gets the sys_id values for the sys_report_summary table entries built by our generators
    var openID = summary_sets.get("Trend of Open Incidents");
    var closedID = summary_sets.get("Trend of Closed Incidents");
    var backLogID = summary_sets.get("Incident Backlog");
 
  // Gets a utility class for dataset manipulation
  var cu =new ChartUtil();
  cu.setTable('incident');
  cu.setColors("#FFDEAD,#7FFF00");
 
  // Gets the dataset for the Open incidents
  var open=new ChartGenerator("bar");open.setSummaryID(openID);var ds =open.getDataset();
  // Gets the dataset for the Closed incidents and combines this with the open incidents into
  // a multi series datasetvar closed =new ChartGenerator("bar");
  closed.setSummaryID(closedID);
  ds = cu.mergeDatasets(ds,"Open", closed.getDataset(),"Closed");
 
  // Gets the chart for the multi series bar chart of open and closed incidents
  var chart = closed.getChart(ds);
 
  // Changes the spacing 
  closed.setNoMargins();
 
  // Adds a line renderer to the chart to show the backlog of incidents
  var line =new ChartGenerator("line");
  line.setSummaryID(backLogID);var lineDS = cu.addEmptyValues(line.getDataset(), ds);
  lineDS = cu.changeDatasetLabel(lineDS,"BackLog");var renderer = line.getChartGenerator().getLineRenderer(Packages.java.awt.Color.RED,3.0,false,true,true);
  closed.addRenderer(renderer, lineDS,true,"Back log");
 
  // returns our chart
  answer = chart;
  • The first part of the code returns the summary set ID values for the data that was created by the generators. These are available via the global variable called summary_sets, which has a get method that takes the name of the generator and returns the ID of the summary set produced by that generator.
    // Gets the sys_id values for the sys_report_summary table entries built by our generatorsvar openID = summary_sets.get("Trend of Open Incidents");var closedID = summary_sets.get("Trend of Closed Incidents");var backLogID = summary_sets.get("Incident Backlog");
  • The next code fragment obtains a new ChartUtil object, initializes the table that it will be going against, and sets up the colors for the two series of data that are produced. Because there is an Open series of data and a Closed series of data, the colors must be established for each series. The methods available in ChartUtil are described later in this page.
    // Gets a utility class for dataset manipulationvar cu =new ChartUtil();
      cu.setTable('incident');
      cu.setColors("#FFDEAD,#7FFF00");
  • The next code fragment gets the dataset (JFreeChart object) that represents the trend of open incidents. This uses the ChartGenerator script include, which reads the summary set data produced by the generator and returns the JFreeChart dataset. The methods available in ChartGenerator are described later in this page.
    // Gets the dataset for the Open incidentsvaropen=new ChartGenerator("bar");open.setSummaryID(openID);var ds =open.getDataset();
  • The next code fragment is similar to the previous sample, but also uses a utility routine to merge the two datasets so that the database contains both the open and the closed data. This condition creates a multi-series dataset that is used to create stacked bar charts via the reporting system. This example, however, combines two totally separate datasets obtained by different generators. This is where you use the colors that were set in the first bit of code. The first color is used for the open items and the second color indicates the closed items.
    // Gets the dataset for the Closed incidents and combines this with the open incidents into
    // a multi series datasetvar closed =new ChartGenerator("bar");
      closed.setSummaryID(closedID);
      ds = cu.mergeDatasets(ds,"Open", closed.getDataset(),"Closed");
  • The next code fragment gets the bar chart that contains the multi-series dataset. This is the JFreeChart chart object that is returned to be displayed.
    // Gets the chart for the multi-series bar chart of open and closed incidentsvar chart = closed.getChart(ds);
  • Normally, there is some spacing between the bars in the multi-series bar chart. There is a helper function in the JFreeChart API to remove this spacing.
    // Changes the spacing 
      closed.setNoMargins();
  • Next, the line is added to the chart that represents the backlog of incidents over the same time frame. This is very similar to the code used to get the other datasets. You need to get the dataset from the summary set data that was created by the generator. For the line to cover the same time span as the open and closed datasets, use the addEmptyValues method of the ChartUtility. This compares the dataset for the line with the dataset for the open or closed data, and then adds empty values where necessary to make the time spans identical. Then, get a JFreeChart line renderer to display the line above the bars. The last item adds the new renderer to the chart.
    // Adds a line renderer to the chart to show the backlog of incidentsvar line =new ChartGenerator("line");
    line.setSummaryID(backLogID);var lineDS = cu.addEmptyValues(line.getDataset(), ds);
    lineDS = cu.changeDatasetLabel(lineDS,"BackLog");var renderer = line.getChartGenerator().getLineRenderer(Packages.java.awt.Color.RED,3.0,false,true,true);
    closed.addRenderer(renderer, lineDS,true,"Back log");
  • Finally, the answer is set to return the chart to the system for display.
    // return our chart
      answer = chart;