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

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

问题描述:

我想按输入的顺序将X和Y坐标连接成一个圆.

I want to connect X and Y coordinates by order which I inputed to make a circle .

我找到了一个用Java绘制X,Y坐标的程序. 然后我添加了我的圆数据,但是程序连接的最近的X,Y坐标未排序X,Y.

I found a program that draw X,Y coordinates in Java . Then I added my data of circle but program connected nearest X,Y coordinates not ordered 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
    );

我期望结果以正方形图表示.

I expected results as square diagram .

The XYSeries API specifies,

默认情况下,系列中的项目将按x值升序排列,并且允许重复使用x值.

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

您可以使用适当的构造函数来克服它,建议此处:

You can defeat this with the appropriate constructor, suggested here:

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

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

In the illustration below, I've added an extra data point to close the figure:

对于任意形状,也请考虑一个XYShapeAnnotation,请参见此处.

For arbitrary shapes, also consider an XYShapeAnnotation, seen here.