如何按添加顺序绘制X,Y坐标? [英] How can I plot X,Y coordinates by added order?

查看:73
本文介绍了如何按添加顺序绘制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.

这篇关于如何按添加顺序绘制X,Y坐标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆