Hi!
I just started using jfreechart and I have some difficulties with the gantt chart.
I created a gantt chart with multiple subtasks. Some of the subtasks from the different tasks are connected and I'd like all the connected subtasks to change color when one of them is clicked.
Does anyone know how to do this?
Gantt Chart : changing subtask color on click
Try something similar to this. It has worked for me.
Set the renderer in the chart.getCategorPlot() to something similar to the above.
Then add a ChartMouseListener to the chartPanel. In the listener get the row and column index of the clicked entity. and set them in the renderer above
Code: Select all
public class SelectionEnabledGanttRenderer extends GanttRenderer {
private int selectedRow=-1;
private int selectedColumn=-1;
@Override
public Paint getItemPaint(int row, int column) {
Paint p = super.getItemPaint(row, column);
if(row==selectedRow && column==selectedColumn){
p = Color.YELLOW;
}
return p;
}
public int getSelectedColumn() {
return selectedColumn;
}
public void setSelectedColumn(int selectedColumn) {
this.selectedColumn = selectedColumn;
}
public int getSelectedRow() {
return selectedRow;
}
public void setSelectedRow(int selectedRow) {
this.selectedRow = selectedRow;
}
}
Then add a ChartMouseListener to the chartPanel. In the listener get the row and column index of the clicked entity. and set them in the renderer above
Code: Select all
public void chartMouseClicked(ChartMouseEvent e) {
if(e.getEntity() != null){
CategoryItemEntity categoryItem = (CategoryItemEntity)e.getEntity();
String selectedName = categoryItem.getColumnKey().toString();
SelectionEnabledGanttRenderer renderer = (SelectionEnabledGanttRenderer)oBase.chart.getCategoryPlot().getRenderer();
renderer.setSelectedRow(0);
renderer.setSelectedColumn(oBase.collection.getColumnIndex(s));
oBase.chart.fireChartChanged();
}
}
Hallo Calisto,
pls how did u manage to create the subtasks and connect them together. Which method did you use, i.e t1.addSubtasks ? or what.
Pls can you send me an example of the codes for subtasks creation and connectivity line . Or you can post it here to also help others.
thanks
susangilbret@yahoo.com
pls how did u manage to create the subtasks and connect them together. Which method did you use, i.e t1.addSubtasks ? or what.
Pls can you send me an example of the codes for subtasks creation and connectivity line . Or you can post it here to also help others.
thanks
susangilbret@yahoo.com