1

I'm using JFreeChart to make a line graph. There are some points that I want to mark, or annotate, with circles of different sizes. I tried ShapeAnnotation, but even after I addAnnotation, it's not visible. I was able to make a pointer annotation, though. Here's the relevant code:

 XYShapeAnnotation annotation = new XYShapeAnnotation(new Ellipse2D.Float(100.0f, 100.0f, 100.0f, 100.0f), new BasicStroke(1.0f), Color.blue);
XYPointerAnnotation pointer = new XYPointerAnnotation("arrow", 0.5,0.5,0.0);
xyDataset.addSeries(series1); //
xyDataset.addSeries(series2); // random lists of numbers
xyDataset.addSeries(series3); //
JFreeChart chart = ChartFactory.createXYLineChart ("XYLine Chart using JFreeChart","Age","Weight",xyDataset,PlotOrientation.VERTICAL,true,true,false);
chart.getXYPlot().addAnnotation(pointer);
chart.getXYPlot().addAnnotation(annotation);

I think I should have more code to make the ellipse annotation visible because I never specified coordinates like I did with the pointer. I went through the JFreeChart API and couldn't find it. Help?

Thomas
  • 139
  • 2
  • 7

1 Answers1

1

It's hard to say why your XYShapeAnnotation fails without seeing your data; an sscce would help. As a starting point, you might look at the examples here and here for comparison.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • It turns out that the circle was way too big and since it wasn't filled and only had an outline, you couldn't see it. Thanks for your answer though, trashgod. I knew I could count on you. You have answers for all the JFreeChart questions. But can I ask you another question? I ended up just making a new series for each circle and setting the shape visible and line invisible. You know how a random color is set for each series? Do you know if there's a way to make one series the same color as another? – Thomas Aug 05 '11 at 00:34
  • I want all the series that contains just the one point marked with a circle to be the same color as the series with the line, if that makes sense. – Thomas Aug 05 '11 at 00:35
  • Yes, I'm a fan. Series colors aren't random; they come from a `DrawingSupplier`. As this sounds like a new question, you might start your research [here](http://stackoverflow.com/questions/3003373/how-to-set-different-colors-to-the-bars-in-stacked-bar-chart-in-ireport/3006785#3006785). You can accept this answer by clicking on the check to the left; see the [faq] for details. – trashgod Aug 05 '11 at 00:47