2

I am a newbie to Java and using JFreechart to display scatter plot.I have a thread which keeps adding points to scatter plot.Color of these points can be different depending upon some property(That is known,not the issue).Currently i am using "XYItemrenderer.setSeriesPaint(0,Color.black);" to change the color but it changes color of all the points.I tried searching and found this-

JFreeChart different colors in different regions for the same dataSeries

But i am confused about how can i pass that information which decides the color of dot to method?

Any help would be appreciated :)

Community
  • 1
  • 1
Anand
  • 1,335
  • 1
  • 12
  • 20

1 Answers1

3

The fact that points differ depending upon some property is the central issue: the defining property needed to assign color is now an attribute of your data model. You can easily change the color in your view's renderer by overriding getItemPaint(), as shown here. The problem then becomes one of accessing the model from the view. The example cited simply references an attribute of the enclosing class, but you may want to pass a model reference to the view explicitly.

image

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • Thanks for your reply, but as i mentioned color of dot is decided based on some other quality and this quality has no relation with row and column number. I found a solution by adding different colored dots to different series. – Anand Feb 16 '14 at 09:22
  • Multiple series is one approach, but it may scale poorly; the view should interrogate the model for the information it needs to render itself. – trashgod Feb 16 '14 at 10:41
  • @trashgod. How did you get that shadow effect on the picture in your answer? – stian Aug 16 '16 at 01:33
  • It's a feature of the Mac OS X [screenshot](http://meta.stackoverflow.com/questions/99734/how-do-i-create-a-screenshot-to-illustrate-a-post). – trashgod Aug 16 '16 at 01:45