如何按添加顺序绘制 X、Y 坐标?

How can I plot X,Y coordinates by added order?

我想按我输入的顺序连接X和Y坐标做一个圆。

我找到了一个在 Java 中绘制 X,Y 坐标的程序。 然后我添加了我的圆数据,但程序连接了最近的 X,Y 坐标而不是有序的 X,Y。

public Graph(final String title) {

    super(title);
    final XYSeries series = new XYSeries("Random Data");

    series.add(2.000 , 0);
    series.add(0 , 2.000);
    series.add(-2.000 , 0);
    series.add(0 , -2.000);
    final XYSeriesCollection data = new XYSeriesCollection(series);
    final JFreeChart chart = ChartFactory.createXYLineChart(
            "XY Series Demo",
            "X",
            "Y",
            data,
            PlotOrientation.VERTICAL,
            true,
            true,
            false
    );

我希望结果是方图。

XYSeriesAPI指定,

By default, items in the series will be sorted into ascending order by x-value, and duplicate x-values are permitted.

您可以使用适当的构造函数来解决这个问题,建议 here:

final XYSeries series = new XYSeries("Random Data", false);

在下图中,我添加了一个额外的数据点来关闭图形:

对于任意形状,还可以考虑 XYShapeAnnotation,见 here