如何改变JFreeChart甘特图中特定子任务的颜色? [英] How to change color of particular sub-task in JFreeChart Gantt Chart?

查看:606
本文介绍了如何改变JFreeChart甘特图中特定子任务的颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含5个任务的甘特图。每个任务分为3个子任务。我需要为每个子任务定义不同的颜色,例如。子任务1:浅蓝色,子任务2:蓝色,子任务3:深蓝色。我试着google了一些例子,但我没有找到任何完整的工作榜样。谢谢。

I have a Gantt Chart with 5 tasks. Each task is divided into 3 sub-tasks. I need to define different color for each sub-task, e.g. Sub-task1: "light blue", Sub-task2: "blue", Sub-task3: "dark blue". I tried to google some examples, but I didn't find any full working example. Thanks.

更新#1:
我正在使用IntervalCategoryDataset作为数据集。

Update#1: I'm using IntervalCategoryDataset for the dataset.

IntervalCategoryDataset dataset = createDataset(data);

final Task t = new Task("Resource " + i, date(time11), date(time14));
t.addSubtask(new Task("Resource " + i, date(time11), date(time12)));
t.addSubtask(new Task("Resource " + i, date(time12), date(time13)));
t.addSubtask(new Task("Resource " + i, date(time13), date(time14)));


推荐答案

您可以覆盖渲染器的 getItemPaint( ) 方法,如此处所述。

You can override the renderer's getItemPaint() method, as discussed here.

附录:由于Gnatt图表使用 GanttRenderer ,您可以执行类似这样的操作来查看现有颜色。只需返回给定行和列的所选颜色。

Addendum: As a Gnatt chart uses a GanttRenderer, you'd do something like this to see the existing colors. Just return your chosen color for a given row and column.

plot.setRenderer(new MyRenderer());
...
private static class MyRenderer extends GanttRenderer {

    @Override
    public Paint getItemPaint(int row, int col) {
        System.out.println(row + " " + col + " " + super.getItemPaint(row, col));
        return super.getItemPaint(row, col);
    }
}

这篇关于如何改变JFreeChart甘特图中特定子任务的颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆