Reputation: 4470
I've drawn a standard normal distribution using JFreeChart:
NormalDistributionFunction2D normalDistributionFunction2D = new NormalDistributionFunction2D(0.5, 0.15);
XYDataset dataset = DatasetUtilities.sampleFunction2D(normalDistributionFunction2D, 0.0, 1.0, 1000, "Normal");
JFreeChart chart = ChartFactory.createXYLineChart("MyTitle --, "", "", xySeriesCollection, PlotOrientation.VERTICAL, false, false, false);
On top of this, I would like to place a circle at a given point. I have no problems with calculating the [x,y] co-ordinates of the circle, but I am unsure as to how I can add it to the chart. Any help appreciated. An MS Paint knockup of what I want to achieve is below.
Upvotes: 1
Views: 3855
Reputation: 113
One way of doing is add a point with x and y coordinates say (0,0) to a series. Now, set renderer.setSeriesShape(series,new Ellipse2D.Double(-3, -3, 6, 6));
now you can update the series and make point moveable aswell.
Upvotes: 0
Reputation: 21439
If you have the point's coordinates, you can:
paintComponent
(a bit difficult as you have to compensate for the chart bordersUpvotes: 1
Reputation: 40851
You absolutely do not need to override the paint method or add a layer on top. JFreeChart already has support for this behavior.
The correct way is to add annotations to the chart, specifically:
chart.getPlot().addAnnotation(new XYShapeAnnotation(new Ellipse2D.Double(x - radius, y - radius, radius + radius, radius + radius))
where x and y is the center of the circle. Note, the coordinates are in your plot space, not the graphical space. JFreeChart will automatically transform them when rendering.
Take a look at: http://www.jfree.org/jfreechart/api/javadoc/org/jfree/chart/annotations/XYShapeAnnotation.htm http://www.java2s.com/Code/Java/Chart/JFreeChartPlotOrientationDemo2.htm
Upvotes: 7