Custom Chart Stacked Bar

Bhupinder1
Giga Expert

Hi,

 

I wanted to create a custom assignment group stacked bar graph like the one listed in below link-

 

JFreeChart: Stacked Bar Chart Demo 4 : Bar Stacked Chart « Chart « Java

 

I'm not very familiar to JFree chart API but if anyone can help in creating the above in ServiceNow that would be great

 

Thanks

Bhupinder

1 ACCEPTED SOLUTION

Hi Kevin,



Thanks for response. But I have little different requirement here that goes-



Let me explain the graph I want to generate




1. Problems Created vs Closed Stacked on Assignment group


2. I'm able to generate garph for all Problems Created vs Closed (Attaching the image)


3. I need to stack on Assignment group for each bar in the above graph like Problems created should be stacked on Assignment group and same for Problems closed


4. As an aletrnative if we can group by Assignment group and for each assignment group if we can show Problems created vs closed that would also do the purpose


5. I'm attaching all the pieces of code that generate graph mentioned in step#2



Below is the graph for which I want to stack on against assignment group



Sample.png


I used custom chart reporting to build above graph and now want to extend the reporting further using Java JFree chart API. For the above graph I used the below piece of code-



Here's the code -



Data Generators


Trend of Open Problems Task


var opened = new SummaryTableWriter("problem_task", '');


  • opened.setTitle("Trend of Open Problems Task");
  • opened.setTrend('opened_at', 'month');
  1. current.summary = opened.generate();
  2. current.setWorkflow(false);
  3. current.update();


Trend of Closed Problems Task


var closed = new SummaryTableWriter("problem_task", '');


  1. closed.setTitle("Trend of Closed Problems Task");
  2. closed.setTrend('closed_at', 'month');
  3. current.summary = closed.generate();
  4. current.setWorkflow(false);
  5. current.update();


Renderer Script


//Get the sys_id values for the sys_report_summary table entries build by our generators


var openID = summary_sets.get("Trend of Open Problems Task");


var closedID = summary_sets.get("Trend of Closed Problems Task");



// Gets a utility class for dataset manipulation


var cu = new ChartUtil();


  1. cu.setTable('problem_task');
  2. cu.setColors("#FFDEAD,#7FFF00");


// Get the dataset for the Open incidents


var open = new ChartGenerator("bar");


  • open.setTable('problem_task');
  • open.setSummaryID(openID);

var ds = open.getDataset();



// Get the dataset for the Closed incidents and combine with the open incidents into


// a multi series dataset


var closed = new ChartGenerator("bar");


  1. closed.setTable('problem_task');
  2. closed.setSummaryID(closedID);

ds = cu.mergeDatasets(ds, "Created", closed.getDataset(), "Closed");



var chart = closed.getChart(ds);



// Change the spacing


  1. closed.setNoMargins();

// return our chart


answer = chart;


View solution in original post

5 REPLIES 5

I believe you would put this code inside a script include, unfortunately I am not an expert at scripting. I am trying myself to do complex graphs with no success.