Reputation: 8928
I'm making an application that takes some data and it needs to make a bar chart, but the color of a bar MUST be related to data that it is representing.
Imagine that I have this kind of data: BANANA 430 WATER MELLON 300
Now I should make a bar chart, and I would like to paint the BANANA bar with yellow paint, and WATER MELLON bar with green paint. I'm using JFreeChart library in java. My research led me to making my custom renderer, but then if I make custom renderer the colors will appear randomly on bars. Any solution for this?
Upvotes: 3
Views: 12690
Reputation: 6239
Here is a demo, where you can see how to do this. As in the comment above, you have to add the paints to the series as you introduced them (0 is the first, 1 is the second and so on).
Upvotes: 2
Reputation: 17849
Maybe this http://www.java2s.com/Code/Java/Chart/JFreeChartBarChartDemo3differentcolorswithinaseries.htm can be of help.
See how the code below is used:
final CategoryItemRenderer renderer = new CustomRenderer(
new Paint[] {Color.red, Color.blue, Color.green,
Color.yellow, Color.orange, Color.cyan,
Color.magenta, Color.blue}
);
Upvotes: 4