docs/examples/MultipleTimeSeries.java
/**
     * Function to play data.
     *
     * @param dataArray dataArray
     */
Function to play data.
@param dataArray dataArray
Function to play data . @param dataArray dataArray
private static void plotData(DataArray dataArray) {
        double[] yData = new double[(int) dataArray.getDataExtent()
                .getElementsProduct()];
        dataArray.getData(yData, dataArray.getDataExtent(), new NDSize());
        int size = yData.length / 2;
        double[] sine = new double[size];
        double[] cosine = new double[size];
        for (int i = 0; i < size; i++) {
            sine[i] = yData[i];
            cosine[i] = yData[i + size];
        }
        SampledDimension dim = dataArray.getDimensions().get(1)
                .asSampledDimension();
        double[] xData = dim.getAxis(size);
        SetDimension set_dim = dataArray.getDimensions().get(0).asSetDimension();
        List<String> labels = set_dim.getLabels();
        DefaultXYDataset dataset = new DefaultXYDataset();
        dataset.addSeries(labels.get(0), new double[][]{xData, sine});
        dataset.addSeries(labels.get(1), new double[][]{xData, cosine});
        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("multiple_time_series_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 ( ) ) ; int size = yData . length / 2 ; double [ ] sine = new double [ size ] ; double [ ] cosine = new double [ size ] ; for ( int i = 0 ; i < size ; i ++ ) { sine [ i ] = yData [ i ] ; cosine [ i ] = yData [ i + size ] ; } SampledDimension dim = dataArray . getDimensions ( ) . get ( 1 ) . asSampledDimension ( ) ; double [ ] xData = dim . getAxis ( size ) ; SetDimension set_dim = dataArray . getDimensions ( ) . get ( 0 ) . asSetDimension ( ) ; List < String > labels = set_dim . getLabels ( ) ; DefaultXYDataset dataset = new DefaultXYDataset ( ) ; dataset . addSeries ( labels . get ( 0 ) , new double [ ] [ ] { xData , sine } ) ; dataset . addSeries ( labels . get ( 1 ) , new double [ ] [ ] { xData , cosine } ) ; 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 ( "multiple_time_series_output.png" ) ; try { ChartUtilities . saveChartAsPNG ( imageFile , chart , 1000 , 600 ) ; } catch ( IOException ioe ) { System . out . println ( "Error" ) ; } }
Function to play data.
Function to play data .
// retrieve information // separate sine and cosine values // get x coordinates data // retrieve labels // Create the chart // save it to a file