Gantt chart의 하위 작업 색을 변경해야합니다. 내 예제는 다음 데이터 집합과 렌더러가있는 GanttDemo2
을 기반으로합니다. 여러 포럼에서이 주제와 관련된 몇 가지 토론을 발견했지만 명확한 간단한 을 찾지 못했습니다. 예제입니다. 특히 작업의 색상을 변경할 수는 있지만 하위 작업을 추출하는 방법을 알지 못합니다.간트 차트의 하위 작업 색을 변경하는 코드
private IntervalCategoryDataset createSampleDataset() {
final TaskSeries s1 = new TaskSeries("Scheduled");
final Task t1 = new Task(
"Design", date(1, Calendar.APRIL, 2001), date(1, Calendar.MAY, 2001));
t1.addSubtask(new Task("Design 1", date(1, Calendar.APRIL, 2001), date(15, Calendar.APRIL, 2001)));
t1.addSubtask(new Task("Design 2", date(16, Calendar.APRIL, 2001), date(25, Calendar.APRIL, 2001)));
t1.addSubtask(new Task("Design 3", date(26, Calendar.APRIL, 2001), date(1, Calendar.MAY, 2001)));
s1.add(t1);
final Task t2 = new Task(
"Proposal", date(1, Calendar.JUNE, 2001), date(1, Calendar.JULY, 2001));
t2.addSubtask(new Task("Proposal 1", date(1, Calendar.JUNE, 2001), date(15, Calendar.JUNE, 2001)));
t2.addSubtask(new Task("Proposal 2", date(16, Calendar.JUNE, 2001), date(25, Calendar.JUNE, 2001)));
t2.addSubtask(new Task("Proposal 3", date(26, Calendar.JUNE, 2001), date(1, Calendar.JULY, 2001)));
s1.add(t2);
final TaskSeriesCollection collection = new TaskSeriesCollection();
collection.add(s1);
return collection;
}
class MyRenderer extends GanttRenderer {
private static final Color subtask1Color = Color.blue;
private static final Color subtask2Color = Color.cyan;
private static final Color subtask3Color = Color.green;
private static final long serialVersionUID = 1L;
public MyRenderer() {
super();
}
@Override
public Paint getItemPaint(int row, int col) {
System.out.println(row + " " + col + " " + super.getItemPaint(row, col));
if (row == 0) {
return subtask1Color;
} else if (row == 1) {
return subtask2Color;
} else if (row == 2) {
return subtask3Color;
} else {
return super.getItemPaint(row, col);
}
}
}
+1 for sscce; 저작권 소스에 대한 링크를 추가했습니다. – trashgod