Customize bar colors in XYJfree chart

馋奶兔 提交于 2019-12-01 22:03:13
Jordan Bentley

What you want to do is the following:

XYPlot plot = (XYPlot) chart.getPlot();
plot.getRenderer().setSeriesPaint(1, Color.yellow);

Replace 1 with the (zero-based) index of the bar whose color you would like to change.

Edit to respond to comment:

List<Color> myBarColors = .....

XYPlot plot = (XYPlot) chart.getPlot();
XYItemRenderer renderer = plot.getRenderer();

for (int i = 0; i < 40; i++) {
    renderer.setSeriesPaint(i, myBarColors.get(i));
}

Edit 2: Misunderstood OPs problem, new solution in comments.

trashgod

The most flexible approach is to override the getItemPaint() method of AbstractRenderer in a custom XYBarRenderer, as shown here for XYLineAndShapeRenderer.

I found the answer Create two series, and then add how many ever bars you want and set color for each series. using setSeriesPaint

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!