Gantt Chart : changing subtask color on click

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
callisto
Posts: 5
Joined: Tue Jul 10, 2007 4:29 pm

Gantt Chart : changing subtask color on click

Post by callisto » Tue Jul 10, 2007 4:38 pm

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?

callisto
Posts: 5
Joined: Tue Jul 10, 2007 4:29 pm

Post by callisto » Wed Jul 18, 2007 8:39 am

Any idea on how to proceed?

MNusinov
Posts: 15
Joined: Tue Jul 03, 2007 7:41 pm

Post by MNusinov » Wed Jul 18, 2007 2:18 pm

Try something similar to this. It has worked for me.

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

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

callisto
Posts: 5
Joined: Tue Jul 10, 2007 4:29 pm

Post by callisto » Wed Aug 01, 2007 5:17 pm

Thank you for your answer.
I tried to implement it but it actually changes the color of all the subtasks in a task. Do you know how I could modify it to change only the color of a subtask?

jblancx
Posts: 24
Joined: Tue Sep 02, 2008 11:27 am
Location: Germany

Post by jblancx » Sun Sep 21, 2008 2:13 pm

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

Locked