How to change color of particular sub-task in JFreeChart Gantt Chart?

筅森魡賤 提交于 2019-12-20 02:30:54

问题


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)));

回答1:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!