
Question:
I am adding an annotation to my plot, but I can't work out how to change the colour or line width (stroke) of this. I've read through the documentation as best as I can but I'm out of ideas. Can anyone help?
Shape shape = new Ellipse2D.Double(circleXValue - radius, circleYValue - radius, radius + radius, radius + radius);
XYShapeAnnotation annotation = new XYShapeAnnotation(shape);
// ??
plot.addAnnotation(annotation);
Answer1:You're using this <a href="http://www.jfree.org/jfreechart/api/javadoc/org/jfree/chart/annotations/XYShapeAnnotation.html#XYShapeAnnotation%28java.awt.Shape%29" rel="nofollow">constructor</a>:
public XYShapeAnnotation(java.awt.Shape shape)
You may want to use one of <a href="http://www.jfree.org/jfreechart/api/javadoc/org/jfree/chart/annotations/XYShapeAnnotation.html#XYShapeAnnotation%28java.awt.Shape,%20java.awt.Stroke,%20java.awt.Paint%29" rel="nofollow">these constructors</a> that specify additional parameters:
public XYShapeAnnotation(
java.awt.Shape shape,
java.awt.Stroke stroke,
java.awt.Paint outlinePaint)
public XYShapeAnnotation(
java.awt.Shape shape,
java.awt.Stroke stroke,
java.awt.Paint outlinePaint,
java.awt.Paint fillPaint)
Answer2:You can find related examples using <a href="http://www.jfree.org/jfreechart/api/javadoc/org/jfree/chart/annotations/XYShapeAnnotation.html#XYShapeAnnotation%28java.awt.Shape,%20java.awt.Stroke,%20java.awt.Paint%29" rel="nofollow">XYShapeAnnotation
</a> <a href="https://stackoverflow.com/a/6620017/230513" rel="nofollow">here</a> and <a href="https://stackoverflow.com/a/8056418/230513" rel="nofollow">here</a>.
<img alt="image 1" class="b-lazy" data-src="https://i.stack.imgur.com/DUp7P.png" data-original="https://i.stack.imgur.com/DUp7P.png" src="https://etrip.eimg.top/images/2019/05/07/timg.gif" />
<img alt="image 2" class="b-lazy" data-src="https://i.stack.imgur.com/4NzNb.png" data-original="https://i.stack.imgur.com/4NzNb.png" src="https://etrip.eimg.top/images/2019/05/07/timg.gif" />