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

1

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

Homelike answered 30/5, 2019 at 14:38 Comment(0)
C
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

Cestus answered 30/5, 2019 at 16:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.