i am using Jfreechart to write a projet of analysing log file, i have a problem of overvide generateToolTip ,what i want to do is when the user move his mouse to a point of
This is a code I've written to extract the description of sub task as the tool tip. It provides each sub-task displaying different tooltip information.
It could not be the best coding sample but it works. You may modify accordingly and use it.
class MyCategoryToolTipGenerator implements CategoryToolTipGenerator
{
HashMap> subTaskMap;
public MyCategoryToolTipGenerator()
{
subTaskMap = new HashMap>();
}
@Override
public String generateToolTip(CategoryDataset categoryDataset, int row, int col )
{
TaskSeriesCollection taskSeriesCollection = (TaskSeriesCollection) categoryDataset;
if ( row >= taskSeriesCollection.getRowCount() )
{
return "";
}
TaskSeries taskSeries = taskSeriesCollection.getSeries( row );
if ( col >= taskSeries.getItemCount() )
{
return "";
}
Task task = taskSeries.get( col );
//Sub Task tooltip handling//
if( task.getSubtaskCount() > 0 )
{
//Task Key for main task
String taskKey = "r=" + row + "c=" + col;
//System.out.println( "Sub Task Count = " + task.getSubtaskCount() + " r=" + row + " c=" + col );
List subTaskList = null;
if( subTaskMap.containsKey( taskKey ) )
{
//If already added, pick the list of available sub tasks
subTaskList = subTaskMap.get( taskKey );
}
else
{
//If not found, add all sub tasks to map
int subTaskCount = task.getSubtaskCount();
subTaskList = new ArrayList( subTaskCount );
for( int i = 0; i < subTaskCount; i++ )
{
//System.out.println("Adding sub task " + task.getSubtask( i ).getDescription());
subTaskList.add( task.getSubtask( i ) );
}
subTaskMap.put( taskKey, subTaskList );
}
if( subTaskList != null && subTaskList.size() > 0 )
{
//Take the top most sub task and remove it from list
Task subTask = subTaskList.remove( 0 );
//System.out.println("Remove sub task " + subTask.getDescription());
//If no other sub tasks available remove key from list
if( subTaskList.size() <= 0 )
{
//System.out.println("Remove Key " + taskKey);
subTaskMap.remove( taskKey );
}
//Return the top most subtask description
return subTask.getDescription();
}
}
return task.getDescription();
}
}