如何在ireport的堆叠条形图中为条形设置不同的颜色? [英] How to set different colors to the bars in stacked bar chart in ireport?

查看:96
本文介绍了如何在ireport的堆叠条形图中为条形设置不同的颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要为堆叠的条形图中的每个条设置唯一的颜色.无论我在一个栏中看到的颜色是什么,都不应在其他任何栏中或其他堆栈中重复出现.

I need to set a unique color to each bar in the stacked bar chart. Whatever the color I see in one bar it shouldn't be repeated in any other bar or any other stack.

例如: 我的报告中有5条.每个酒吧有3个不同的堆栈.我想将与红色相关的颜色应用于第一个栏及其堆栈.第二栏应具有蓝色的相关颜色.等等.. 如图所示.该图显示了我们想要的一个非常基本的要求.只是使用普通的ms绘画创建的. 堆叠式Bar MS Paint图像

For example: I have 5 bars in the report. Each bar has 3 different stacks. I want to apply a red related colors to the first bar and its stacks. Second bar should have blue related colors. etc.. It is showed in the attached image. The image shows a very basic requirement what we want. Just created using a normal ms paint. Stacked Bar MS Paint Image

推荐答案

您可以覆盖

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);
    }
}

这篇关于如何在ireport的堆叠条形图中为条形设置不同的颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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