1

I am drawing a histogram in JFreeChart. The columns of the histogram are colored red. But each column also has a white stripe on its left side. This stripe looks like a reflection effect. How can I remove the reflection effect to get solid colored bars instead? For more information, please see the attached screenshot.

Histogram with Reflection Effect

Brian Schack
  • 300
  • 3
  • 14
  • 1
    Try `StandardBarPainter`, examined [here](https://stackoverflow.com/q/7076305/230513). If this is not a duplicate, please [edit] your question to include a [mre] that shows your revised approach. – trashgod Oct 10 '22 at 18:05
  • 1
    More examples are pictured [here](https://stackoverflow.com/search?q=user%3A230513+setBarPainter). – trashgod Oct 11 '22 at 15:57
  • @trashgod Yes, that worked! That question refers to a CategoryPlot, and my question refers to an XYPlot. But in both answers, we use the setBarPainter method. I also found a related question that you answered: "How to change JFreeChart vertical bar to a solid color?" https://stackoverflow.com/questions/71025895/how-to-change-jfreechart-vertical-bar-to-a-solid-color/71027246 – Brian Schack Oct 13 '22 at 16:07
  • @trashgod I disagree with one of the three questions marked as duplicates: "JFreeChart MouseListener doesn't resolve chart elements." That question relates to listening for mouse events, and this question relates to drawing a reflection effect. I agree with the other two duplicate questions. https://stackoverflow.com/questions/7999587/jfreechart-mouselistener-doesnt-resolve-chart-elements – Brian Schack Oct 14 '22 at 17:24
  • Your point is well taken, but the illustration, like yours, may guide future users. If you disagree, please don't hesitate to flag for moderator attention or post on [MetaSO](https://meta.stackoverflow.com/search?q=tangential+duplicates). As you had some trouble locating the answer, I'd welcome additions. – trashgod Oct 14 '22 at 17:39

1 Answers1

1

The following code sets the bar painter for the histogram to the StandardXYBarPainter which does not draw a reflection effect. For more information, please see the related questions JFreeChart BarChart -> NO gradient and How to change JFreeChart vertical bar to a solid color? When I searched for my question, I did not see those questions because I searched for the word 'reflection' instead of 'gradient'. @trashgod referred me to these questions in his comment.

((XYBarRenderer) ((XYPlot) histogram.getPlot()).getRenderer()).setBarPainter(new StandardXYBarPainter());
Brian Schack
  • 300
  • 3
  • 14