Reputation: 535
I've based my application on the StackedBarChart4.java demo program.
I need to develop an algorithm that will accurately paint the stacked bar sections given that will vary each time the application is run.
The challenge is how to iterate though the series that is used in the following statement:
renderer.setSeriesPaint(int Series, P Paint);
What exactly the Series represented by the int? It seems to be based on the rowkey elements for one category. But which one since they all may have different values some of which may be null.
Thanks
Elliot
Upvotes: 1
Views: 179
Reputation: 535
The jFree developers guide says that each row in a dataset is series. Each column is a category. I decided to just examine all the keys returned by dataset.getRowKey() for one category or date. Whether the associated values were null or not doesn't matter.
In my case each key is composed of a skill and employee in the form "skill (employee)" and iterating through the rowkeys allows me to find the correct color positions in each of the bars for the different employees.
Every time a get a different key I parse out the particular employee and apply the correct paint to it based on the employees position in the color array.
I must be doing something right since it's working.
Here's the code:
Paint[] p = new Paint[emps.size()];
.
.
.
// need to do this for but all rows or series points whether they have a null value or not
for (int rowNdx = 0; rowNdx < dataset.getRowKeys().size(); rowNdx++) {
//parse out the emp and use the emp hashtable to get the correct offset in the color array
String emp = getEmp(dataset.getRowKey(rowNdx).toString()); // will extract emp number from skill/emp rowkey e.g. "0550 (02195)"
int foo = Integer.parseInt(empsHash.get(emp).toString()); // will get offset in emp arraylist for this employee number
renderer.setSeriesPaint(rowKey, p[foo]); // paint this series Pos is the series number and always start with position of the employee in the
if (debug)System.out.print("\n");
}
Here's the chart it produces. The legend indicates the colors for the different employees who have worked on the skill on each date.
Upvotes: 1