JFreeChart中PieChart的颜色

问题描述 投票:2回答:2

我希望生成随机颜色,这在饼图中很有吸引力。当涉及到GUI时,我的意识很差。任何人都可以帮助编写一个函数,它可以生成6种颜色,可能在饼图中看起来不错。随机顺序。现在我有硬编码。但我不喜欢那些颜色。请帮帮我。

plot.setSectionPaint("iPhone 2G", new Color(200, 255, 255));
plot.setSectionPaint("iPhone 3G", new Color(200, 200, 255));
java colors jfreechart
2个回答
6
投票

我的建议是不要生成随机颜色有两个原因。首先,你必须采取额外的步骤,以确保两种或多种颜色不太相似。其次,颜色是情绪化的。你不希望你的“这个图表告诉我一切都很好”颜色要鲜红。红色是警示色;橙色和黄色也是如此。

图表中颜色的一般建议是使用不饱和颜色作为常规数据,使用更明亮的颜色来表示您想要引起注意的数据。我不确定你的确切用例,但如果你想引起人们对特别高的iPhone 3GS销售的关注,你可能想要使用更亮的颜色,如果它超过一定的阈值。

作为一种入门手段,我会使用VonC's answer中的颜色图表来手工挑选5种颜色。你不应该在一张图表上显示太多不同的颜色,因为观众有效地收集的数据太多。如果你在图表上有超过7个左右的数据集,那么很有可能你没有显示正确的图表! (但这是另一个故事......)

确保所选颜色之间没有冲突,并将它们排列成阵列。现在,每次着色图表时都可以使用简单的列表。

public class ChartColorSource {
    public static final Color[] COLORS;
    static {
        COLORS = new Color[ 6 ];
        COLORS[0] = new Color( ... );
        COLORS[1] = new Color( ... );
        COLORS[2] = new Color( ... );
        COLORS[3] = new Color( ... );
        COLORS[4] = new Color( ... );
        COLORS[5] = new Color( ... );
    }

    /**
     * Assign a color from the standard ones to each category
     */
    public static void colorChart( Plot plot, String[] categories ) {
        if ( categories.length > COLORS.length ) {
            // More categories than colors. Do something!
            return;
        }

        // Use the standard colors as a list so we can shuffle it and get 
        // a different order each time.
        List<Color> myColors = Arrays.asList( COLORS );
        Collections.shuffle( myColors );

        for ( int i = 0; i < categories.length; i++ ) {
            plot.setSectionPaint( categories[i], myColors.get( i ) );
        }
    }
}

7
投票

我建议使用一些color charts的颜色,而不是尝试生成随机颜色。

你有一些桌子颜色为graphs and charts

alt text http://www.sapdesignguild.org/goodies/diagram_guidelines/PALETTES/PALETTE1.GIF

另见Recommendations for Charts and Graphics

alt text (来源:sapdesignguild.org

© www.soinside.com 2019 - 2024. All rights reserved.