I have an arraylist of points I want to include in a JFreeChart scatterplot. That works fine, but I now want a best fit line on it. After some searching, JFreeChart doesn't support such calculations directly, so what I want to do is calculate it myself and then stick a line into the chart manually. How do I get a line in a scatterplot?
XYSeries series = new XYSeries("Data");
for (Point p : points) {
series.add(p.getX(), p.getY());
}
XYSeriesCollection dataset = new XYSeriesCollection(series);
JFreeChart chart = ChartFactory.createScatterPlot(chartName, "Mass", parameter, dataset, PlotOrientation.VERTICAL, false, true, true);
return chart;