94 lines
2.4 KiB
Java
94 lines
2.4 KiB
Java
package View;
|
|
|
|
import Model.Pair;
|
|
import org.jfree.chart.ChartFactory;
|
|
import org.jfree.chart.ChartPanel;
|
|
import org.jfree.chart.JFreeChart;
|
|
import org.jfree.chart.plot.PlotOrientation;
|
|
import org.jfree.chart.plot.XYPlot;
|
|
import org.jfree.chart.renderer.xy.XYItemRenderer;
|
|
import org.jfree.data.xy.XYSeries;
|
|
import org.jfree.data.xy.XYSeriesCollection;
|
|
import org.jfree.util.ShapeUtilities;
|
|
|
|
import javax.swing.*;
|
|
import java.awt.*;
|
|
import java.util.LinkedList;
|
|
|
|
/**
|
|
* Implementierung verschiedener Algorithmen zur Berechnung von Ausgleichsgeraden.
|
|
*
|
|
* @Author: Armin Wolf
|
|
* @Email: a_wolf28@uni-muenster.de
|
|
* @Date: 29.05.2017.
|
|
*/
|
|
public class PlotDialog extends JPanel {
|
|
|
|
private JFreeChart chart;
|
|
private ChartPanel panel;
|
|
private XYSeriesCollection datapoints;
|
|
private XYSeries series;
|
|
|
|
public PlotDialog() {
|
|
super();
|
|
this.setPreferredSize(new Dimension(800, 500));
|
|
}
|
|
|
|
public void createPlot(LinkedList<Pair> points) {
|
|
|
|
Thread thread = new Thread(new Runnable() {
|
|
@Override
|
|
public void run() {
|
|
System.out.println("start");
|
|
|
|
convertData(points);
|
|
}
|
|
});
|
|
thread.start();
|
|
try {
|
|
thread.join();
|
|
} catch (InterruptedException e) {
|
|
e.printStackTrace();
|
|
}
|
|
|
|
chart = ChartFactory.createScatterPlot("",
|
|
"X", "Y", datapoints, PlotOrientation.VERTICAL, false, true, false);
|
|
Shape diamond = ShapeUtilities.createDiamond(2f);
|
|
chart.setBorderVisible(false);
|
|
chart.setAntiAlias(true);
|
|
chart.getPlot().setBackgroundPaint(Color.WHITE);
|
|
|
|
XYPlot xyPlot = (XYPlot) chart.getPlot();
|
|
xyPlot.setDomainCrosshairVisible(true);
|
|
xyPlot.setRangeCrosshairVisible(true);
|
|
|
|
XYItemRenderer renderer = xyPlot.getRenderer();
|
|
renderer.setSeriesPaint(0, Color.blue);
|
|
renderer.setSeriesShape(0, diamond);
|
|
|
|
xyPlot.setDomainCrosshairVisible(true);
|
|
xyPlot.setRangeCrosshairVisible(true);
|
|
|
|
panel = new ChartPanel(chart);
|
|
this.add(panel);
|
|
}
|
|
|
|
public void addLineToPlot() {
|
|
//TODO Line Estimator
|
|
}
|
|
|
|
private void convertData(LinkedList<Pair> points) {
|
|
|
|
datapoints = new XYSeriesCollection();
|
|
series = new XYSeries("");
|
|
for (Pair p : points) {
|
|
series.add(p.getX(), p.getY());
|
|
}
|
|
|
|
datapoints.addSeries(series);
|
|
}
|
|
|
|
|
|
}
|
|
|