Skip to content

howto bar plot colors

Erich Seifert edited this page Sep 21, 2017 · 3 revisions

How can I set the colors for the bars in a bar plot?

Bar plots use the BarRenderer class to render each bar. The BarRenderer is a point renderer and is able to use a single color or a color mapper to select colors for each bar.

For example, to set a single color for all bars:

PointRenderer barRenderer = plot.getPointRenderers(data).get(0);
barRenderer.setColor(Color.RED);

To blend two colors over all bars:

PointRenderer barRenderer = plot.getPointRenderers(data).get(0);
LinearGradient colorMapper = new LinearGradient(Color.RED, Color.BLUE);
colorMapper.setRange(0, data.getRowCount());
barRenderer.setColor(colorMapper);