Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Java中从ArrayList生成折线图_Java_Opencv_Arraylist_Graph_Jfreechart - Fatal编程技术网

如何在Java中从ArrayList生成折线图

如何在Java中从ArrayList生成折线图,java,opencv,arraylist,graph,jfreechart,Java,Opencv,Arraylist,Graph,Jfreechart,我正在使用OpenCV在eclipse上执行对象跟踪。我用一个摄像头记录了一架RC直升机飞越我的起居室。该程序运行良好,并用一个矩形来限制直升机。现在我想输出一个显示直升机飞行的图表。我基本上将所有矩形的中心保存在两个单独的列表中,初始化如下: xPositions = new ArrayList<Integer>(); yPositions = new ArrayList<Integer>(); 你用谷歌搜索过任何教程吗?这一个似乎适合您正在做的事情:扩展Abs

我正在使用OpenCV在eclipse上执行对象跟踪。我用一个摄像头记录了一架RC直升机飞越我的起居室。该程序运行良好,并用一个矩形来限制直升机。现在我想输出一个显示直升机飞行的图表。我基本上将所有矩形的中心保存在两个单独的列表中,初始化如下:

xPositions = new ArrayList<Integer>();  
yPositions = new ArrayList<Integer>(); 

你用谷歌搜索过任何教程吗?这一个似乎适合您正在做的事情:扩展
AbstractXYDataset
,如图所示。如果您有问题,请编辑您的问题,以包括一个显示您当前方法的问题。
    public MakesLineChart(final String title, List<Integer> xCoordinatesConstructor, List<Integer> yCoordinatesConstructor ) {

        super(title);

        final XYDataset dataset = createDataset(xCoordinatesConstructor, yCoordinatesConstructor);
        final JFreeChart chart = createChart(dataset);
        final ChartPanel chartPanel = new ChartPanel(chart);
        chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
        setContentPane(chartPanel);

    }

    private XYDataset createDataset(List<Integer> xCoordinates, List<Integer> yCoordinates) {


        final XYSeries series1 = new XYSeries("Position");
        if(xCoordinates.size()==yCoordinates.size()){
            for(int i=0;i<xCoordinates.size();i++ ){
                series1.add(xCoordinates.get(i), yCoordinates.get(i));
            }
        }


        final XYSeriesCollection dataset = new XYSeriesCollection();
        dataset.addSeries(series1);


        return dataset;

    }

    private JFreeChart createChart(final XYDataset dataset) {

        // create the chart...
        final JFreeChart chart = ChartFactory.createXYLineChart(
            "Position Plot",      // chart title
            "X",                      // x axis label
            "Y",                      // y axis label
            dataset,                  // data
            PlotOrientation.VERTICAL,
            true,                     // include legend
            true,                     // tooltips
            false                     // urls
        );

        // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
        chart.setBackgroundPaint(Color.white);


        // get a reference to the plot for further customisation...
        final XYPlot plot = chart.getXYPlot();
        plot.setBackgroundPaint(Color.lightGray);
    //    plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
        plot.setDomainGridlinePaint(Color.white);
        plot.setRangeGridlinePaint(Color.white);

        final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
        renderer.setSeriesLinesVisible(0, false);
        renderer.setSeriesShapesVisible(1, false);
        plot.setRenderer(renderer);

        // change the auto tick unit selection to integer units only...
        final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
        rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
        // OPTIONAL CUSTOMISATION COMPLETED.

        return chart;

    }

}