docs/examples/RegularlySampledData.java
/**
     * Function to plot data.
     *
     * @param dataArray data array
     */
Function to plot data.
@param dataArray data array
Function to plot data . @param dataArray data array
private static void plotData(DataArray dataArray) {
        double[] yData = new double[(int) dataArray.getDataExtent()
                .getElementsProduct()];
        dataArray.getData(yData, dataArray.getDataExtent(), new NDSize());
        SampledDimension dim = dataArray.getDimensions().get(0)
                .asSampledDimension();
        double[] xData = dim.getAxis(yData.length);
        DefaultXYDataset dataset = new DefaultXYDataset();
        dataset.addSeries("Sine", new double[][]{xData, yData});
        JFreeChart chart = ChartFactory.createXYLineChart(dataArray.getName(),
                dim.getLabel() + " [" + dim.getUnit() + "]",
                dataArray.getLabel() + " [" + dataArray.getUnit() + "]",
                dataset, PlotOrientation.VERTICAL, false, false, false);
        chart.getXYPlot().getRenderer().setSeriesPaint(0, Color.BLUE);
        chart.getPlot().setBackgroundPaint(Color.WHITE);
        java.io.File imageFile = new java.io.File("regularly_sampled_data_output.png");
        try {
            ChartUtilities.saveChartAsPNG(imageFile, chart, 1000, 600);
        } catch (IOException ioe) {
            System.out.println("Error");
        }
    }
private static void plotData ( DataArray dataArray ) { double [ ] yData = new double [ ( int ) dataArray . getDataExtent ( ) . getElementsProduct ( ) ] ; dataArray . getData ( yData , dataArray . getDataExtent ( ) , new NDSize ( ) ) ; SampledDimension dim = dataArray . getDimensions ( ) . get ( 0 ) . asSampledDimension ( ) ; double [ ] xData = dim . getAxis ( yData . length ) ; DefaultXYDataset dataset = new DefaultXYDataset ( ) ; dataset . addSeries ( "Sine" , new double [ ] [ ] { xData , yData } ) ; JFreeChart chart = ChartFactory . createXYLineChart ( dataArray . getName ( ) , dim . getLabel ( ) + " [" + dim . getUnit ( ) + "]" , dataArray . getLabel ( ) + " [" + dataArray . getUnit ( ) + "]" , dataset , PlotOrientation . VERTICAL , false , false , false ) ; chart . getXYPlot ( ) . getRenderer ( ) . setSeriesPaint ( 0 , Color . BLUE ) ; chart . getPlot ( ) . setBackgroundPaint ( Color . WHITE ) ; java . io . File imageFile = new java . io . File ( "regularly_sampled_data_output.png" ) ; try { ChartUtilities . saveChartAsPNG ( imageFile , chart , 1000 , 600 ) ; } catch ( IOException ioe ) { System . out . println ( "Error" ) ; } }
Function to plot data.
Function to plot data .
// retrieve data // get x coordinates data // Create the chart // save it to a file