3

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)));
Klausos Klausos
  • 15,308
  • 51
  • 135
  • 217

1 Answers1

3

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);
    }
}
Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • I read this topic, but I don't understand what shoul be the whole solution. I need some small and clear example. – Klausos Klausos Jan 18 '12 at 21:15
  • I tried this code. But I don´t understand where the Colors of sub-tasks are defined? If I do only this, then all sub-tasks still have the same blue color. – Klausos Klausos Jan 19 '12 at 12:10
  • Where do I need to use getHSBColor()? Inside the getItemPaint or where? – Klausos Klausos Jan 19 '12 at 12:14
  • It looks like `getItemPaint()` receives the row and column, but you'll have to query the model to `getSubtaskCount()`. I'm seeing two passes, but you can override `drawItem()` to be sure. – trashgod Jan 19 '12 at 20:15
  • Could you please provide an example with getSubtaskCount()? I would not like to use drawItem() as it's less flexible method. – Klausos Klausos Jan 19 '12 at 21:18
  • 1
    A complete example is beyond the scope of SO. You can probably assume two passes as a start. It's your data model; just invoke `getSubtaskCount()` on the relevant `Task`. An [sscce](http://sscce.org/) that shows representative data and color selection may help. – trashgod Jan 19 '12 at 21:54