3

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 .result_ss

1 Answers1

3

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:

image

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

image

trashgod
  • 203,806
  • 29
  • 246
  • 1,045