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

↘锁芯ラ 提交于 2021-01-28 01:15:10

问题


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

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 .


回答1:


The XYSeries API specifies,

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:

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



来源:https://stackoverflow.com/questions/56380419/how-can-i-plot-x-y-coordinates-by-added-order

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!