且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在ireport的堆叠条形图中为条形设置不同的颜色?

更新时间:2023-01-27 08:04:03

您可以覆盖 StackedBarRenderer() 返回所需的颜色.您可以使用

You can override the getItemPaint() method of StackedBarRenderer() to return the desired color. You can use getHSBColor() to construct related colors by varying the brightness or saturation for a given hue.

附录:下面的示例将打印出每个项目的行,列和颜色.您可以将结果用作要返回哪种自定义颜色的指南.参见 BarChartDemo1 (用于示例数据集).

Addendum: The example below will print out the row, column and color for each item. You can use the result as a guide to which custom color you want to return. See BarChartDemo1 for a sample dataset.

plot.setRenderer(new MySBRenderer());
...
private static class MySBRenderer extends StackedBarRenderer {

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