package umontreal.iro.lecuyer.charts;

import   org.jfree.data.xy.XYSeries;
import   org.jfree.data.xy.XYSeriesCollection;
import   org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;


/**
 * This class extends 
 * {@link umontreal.iro.lecuyer.charts.XYListSeriesCollection XYListSeriesCollection}.
 * The data is given as lists of y-coordinates. The x-coordinates are
 * simply the indices + 1 of each y-coordinate in the given lists.
 * 
 */
public class YListSeriesCollection extends XYListSeriesCollection  {



   /**
    * Creates a new YListSeriesCollection instance with default
    *    parameters and given data series.
    *    The input vectors represent sets of plotting data.
    *    More specifically, each vector data represents a y-coordinates set.
    *    Position in the vector will form the x-coordinates. Indeed the value
    *    data[j] corresponds to the point 
    *    
    * (j + 1,data[j]) on the chart.
    * 
    * @param data series of point sets.
    * 
    * 
    */
   public YListSeriesCollection (double[]... data)  {
      renderer = new XYLineAndShapeRenderer();
      ((XYLineAndShapeRenderer)renderer).setShapesVisible(false);
      seriesCollection = new XYSeriesCollection();

      XYSeriesCollection tempSeriesCollection =
          (XYSeriesCollection)seriesCollection;
      for (int i = 0; i < data.length; i ++) {
         XYSeries serie = new XYSeries(" ");
         for (int j = 0; j < data[i].length; j++)
            serie.add(j+1, data[i][j]);
         tempSeriesCollection.addSeries(serie);
      }

      // set default colors
      for(int i = 0; i < tempSeriesCollection.getSeriesCount(); i++) {
         renderer.setSeriesPaint(i, getDefaultColor(i));
      }

      // set default plot style
      plotStyle = new String[tempSeriesCollection.getSeriesCount()];
      marksType = new String[tempSeriesCollection.getSeriesCount()];
      dashPattern = new String[tempSeriesCollection.getSeriesCount()];
      for (int i = 0; i < tempSeriesCollection.getSeriesCount(); i++) {
         marksType[i] = " ";
         plotStyle[i] = "smooth";
         dashPattern[i] = "solid";
      }
   }


   /**
    * Creates a new YListSeriesCollection instance with default
    *    parameters and one data series.
    *    The vector data represents a set of plotting data.
    *    Position in the vector represents the x-coordinate of the points:
    *     thus the coordinates of the points are given by
    *    
    * (j + 1,data[j]).
    *   However, only the first numPoints of data will
    *   be considered in the series.
    * 
    * @param data point set.
    * 
    *    @param numPoints Number of points to plot
    * 
    * 
    */
   public YListSeriesCollection (double[] data, int numPoints)  {
      renderer = new XYLineAndShapeRenderer();
      ((XYLineAndShapeRenderer)renderer).setShapesVisible(false);
      seriesCollection = new XYSeriesCollection();

      XYSeriesCollection tempSeriesCollection =
          (XYSeriesCollection)seriesCollection;
      XYSeries serie = new XYSeries(" ");
      for (int j = 0; j < numPoints; j++)
         serie.add(j+1, data[j]);
      tempSeriesCollection.addSeries(serie);

      // set default colors
      renderer.setSeriesPaint(0, getDefaultColor(0));

      // set default plot style
      plotStyle = new String[1];
      marksType = new String[1];
      dashPattern = new String[1];
      marksType[0] = " ";
      plotStyle[0] = "smooth";
      dashPattern[0] = "solid";
   }


   /**
    * Creates a new YListSeriesCollection instance with default
    *    parameters and given data series.
    *    The matrix data represents a set of plotting data.
    *    More specifically, each row of data represents a y-coordinates set.
    *    Position in the vector will form the x-coordinates. Indeed, for each serie
    *    i, the value data[i][j] corresponds to the point 
    *    
    * (j + 1,data[j]) on the chart.
    *   However, only the first numPoints of data will
    *   be considered for each series of points.
    * 
    * @param data series of point sets.
    * 
    *    @param numPoints Number of points to plot
    * 
    */
   public YListSeriesCollection (double[][] data, int numPoints)  {
      renderer = new XYLineAndShapeRenderer();
      ((XYLineAndShapeRenderer)renderer).setShapesVisible(false);
      seriesCollection = new XYSeriesCollection();

      XYSeriesCollection tempSeriesCollection =
          (XYSeriesCollection)seriesCollection;
      for (int i = 0; i < data.length; i ++) {
         XYSeries serie = new XYSeries(" ");
         for (int j = 0; j < numPoints; j++)
            serie.add(j+1, data[i][j]);
         tempSeriesCollection.addSeries(serie);
      }

      // set default colors
      for(int i = 0; i < tempSeriesCollection.getSeriesCount(); i++) {
         renderer.setSeriesPaint(i, getDefaultColor(i));
      }

      // set default plot style
      plotStyle = new String[tempSeriesCollection.getSeriesCount()];
      marksType = new String[tempSeriesCollection.getSeriesCount()];
      dashPattern = new String[tempSeriesCollection.getSeriesCount()];
      for (int i = 0; i < tempSeriesCollection.getSeriesCount(); i++) {
         marksType[i] = " ";
         plotStyle[i] = "smooth";
         dashPattern[i] = "solid";
      }
   }
}

 

Ads help maintain this website.