How to set Jfree GanttChart Subtasks Color and labels
Asked Answered
M

1

1

I am using the Jfree Charts to display Gantt Chart.I have to display differnt colors to the subtasks that are present under one series.

For Example if I have 5 tasks in series One: each task should have different color Also,I need to print label for each task .

I tried many ways but not successful and could only set the series color alone.

Please can any one help.

Thank you.

Mahoney answered 11/2, 2011 at 13:25 Comment(0)
S
1

One approach is to override getItemPaint() in your subclass of GanttRenderer. Just return a different color for each column.

Addendum:

I would need to paint the subtask depending on the task completed or not irrespective of the column value.

If I understand, you would return the completed color if that column was completed; otherwise return the non-completed color.

However, please can [you] send a code snippet.

This example should help you see the relationship between row/column and series/item.

Also, could you please let me know how to print the labels on the subtasks.

Because, a GanttRenderer is an IntervalBarRenderer, I'd look at a IntervalCategoryItemLabelGenerator.

It's not really working.

What's not working? You haven't posted any code. The example cited is a modification to the standard BarChartDemo1; it produces the following output. Note in particular how there are three series (parameter row), each having five values (parameter col). The super implementation of getItemPaint() simply returns the series paints in a cycle. Your would override that behavior to do whatever your application requires.

0 0 java.awt.GradientPaint@7e1a9d1b
1 0 java.awt.GradientPaint@540984b
2 0 java.awt.GradientPaint@53ce669e
0 1 java.awt.GradientPaint@7e1a9d1b
1 1 java.awt.GradientPaint@540984b
2 1 java.awt.GradientPaint@53ce669e
0 2 java.awt.GradientPaint@7e1a9d1b
1 2 java.awt.GradientPaint@540984b
2 2 java.awt.GradientPaint@53ce669e
0 3 java.awt.GradientPaint@7e1a9d1b
1 3 java.awt.GradientPaint@540984b
2 3 java.awt.GradientPaint@53ce669e
0 4 java.awt.GradientPaint@7e1a9d1b
1 4 java.awt.GradientPaint@540984b
2 4 java.awt.GradientPaint@53ce669e
Stomy answered 11/2, 2011 at 17:9 Comment(3)
Hi, I would need to paint the subtask depending on the task completed or not irrespective of the column value..@trashgold However,please can u send code snippet. Also,could you please let me know how to print the labels on the ubstasks. Thank you.Mahoney
Hi I tried using it but not successful with the code I have.Can u please send me a basic example code showing with few subtasks labels on the Gantt Bars.Mahoney
@Med: the example I cited above is a straightforward extension to a category demo that comes with JFreeChart. You can start with it to construct an sscce that clarifies your problem sscce.orgStomy

© 2022 - 2024 — McMap. All rights reserved.