How to set Jfree GanttChart Subtasks Color and labels

早过忘川 提交于 2019-12-20 05:27:04

问题


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.


回答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


来源:https://stackoverflow.com/questions/4969494/how-to-set-jfree-ganttchart-subtasks-color-and-labels

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!