I have a Gantt Chart with 5 tasks. Each task is divided into 3 sub-tasks. I need to define different color for each sub-task, e.g. Sub-task1: "light blue", Sub-task2: "blue", Sub-task3: "dark blue". I tried to google some examples, but I didn't find any full working example. Thanks.
Update#1: I'm using IntervalCategoryDataset for the dataset.
IntervalCategoryDataset dataset = createDataset(data);
final Task t = new Task("Resource " + i, date(time11), date(time14));
t.addSubtask(new Task("Resource " + i, date(time11), date(time12)));
t.addSubtask(new Task("Resource " + i, date(time12), date(time13)));
t.addSubtask(new Task("Resource " + i, date(time13), date(time14)));
trashgod
You can override the renderer's getItemPaint()
method, as discussed here.
Addendum: As a Gnatt chart uses a GanttRenderer
, you'd do something like this to see the existing colors. Just return your chosen color for a given row and column.
plot.setRenderer(new MyRenderer());
...
private static class MyRenderer extends GanttRenderer {
@Override
public Paint getItemPaint(int row, int col) {
System.out.println(row + " " + col + " " + super.getItemPaint(row, col));
return super.getItemPaint(row, col);
}
}
来源:https://stackoverflow.com/questions/8914932/how-to-change-color-of-particular-sub-task-in-jfreechart-gantt-chart