简体   繁体   中英

How can i assign different colors to each dot in scatter plot using jfreechart in java?

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 :)

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.

图片

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM