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.
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