コード例 #1
0
  @Override
  protected void setChart() {
    SeriesManager<Double, Double> sf = new SeriesManager<Double, Double>(intermediateData);
    List<DataSeries<Double, Double>> seriesList = sf.getSeries();

    DataSeries<Double, Double> series = seriesList.get(0);
    List<SeriesPair<Double, Double>> values = series.getSeriesValues(Double.class, Double.class);

    XYSeries deltaMassSeries = new XYSeries(series.getIdentifier());
    for (SeriesPair<Double, Double> value : values) {
      deltaMassSeries.add(value.getX(), value.getY());
    }

    XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.addSeries(deltaMassSeries);

    chart =
        ChartFactory.createXYLineChart(
            getChartTitle(), // chart title
            "Experimental m/z - Theoretical m/z", // x axis label
            "Relative Frequency", // y axis label
            dataset, // chartData
            PlotOrientation.VERTICAL,
            false, // include legend
            true, // tooltips
            false // urls
            );
    chart.addSubtitle(new TextTitle(getChartSubTitle()));

    XYPlot plot = chart.getXYPlot();
    plot.setDomainZeroBaselineVisible(true);
    plot.setBackgroundAlpha(0f);
    plot.setDomainGridlinePaint(Color.red);
    plot.setRangeGridlinePaint(Color.blue);
  }
コード例 #2
0
  private DataSeries<Integer, Integer> getAllSpectraSeries(
      List<DataSeries<Integer, Integer>> seriesList) {
    List<Integer> keys = new ArrayList<Integer>();
    Map<Integer, Integer> map = new HashMap<Integer, Integer>();
    for (DataSeries<Integer, Integer> series : seriesList) {
      for (SeriesPair<Integer, Integer> sp : series.getSeriesValues(Integer.class, Integer.class)) {
        Integer key = sp.getX();
        Integer value = map.containsKey(key) ? map.get(key) + sp.getY() : sp.getY();

        if (!keys.contains(key)) keys.add(key);
        map.put(key, value);
      }
    }

    List<SeriesPair<Integer, Integer>> seriesPairs = new ArrayList<SeriesPair<Integer, Integer>>();
    for (Integer key : keys) {
      Integer value = map.get(key);
      SeriesPair<Integer, Integer> seriesPair = new SeriesPair<Integer, Integer>(key, value);
      seriesPairs.add(seriesPair);
    }

    return new DataSeries<Integer, Integer>(
        DataSeriesType.ALL_SPECTRA, DataSeriesType.ALL_SPECTRA.getType(), seriesPairs);
  }
コード例 #3
0
  @Override
  protected void setChart() {
    SeriesManager<Integer, Integer> sf = new SeriesManager<Integer, Integer>(intermediateData);
    List<DataSeries<Integer, Integer>> seriesList = sf.getSeries();

    // Adds the 'All Spectra' series at the end in the local variable 'seriesList'
    // **NOTE** The intermediateData is NOT modified
    seriesList.add(getAllSpectraSeries(seriesList));

    List<Color> seriesColor = new ArrayList<Color>();
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    for (DataSeries<Integer, Integer> series : seriesList) {
      DataSeriesType seriesType = series.getType();
      if (!visibleTypes.contains(seriesType)) continue;

      String serieKey = series.getIdentifier();
      List<SeriesPair<Integer, Integer>> values =
          series.getSeriesValues(Integer.class, Integer.class);

      Map<String, Integer> map = new HashMap<String, Integer>();
      // The map is filled with the intermediate data values
      int greaterThanTopValue = 0;
      for (SeriesPair<Integer, Integer> value : values) {
        int xValue = value.getX();
        int yValue = value.getY();
        if (xValue > TOP_VALUE) {
          greaterThanTopValue += yValue;
        } else {
          map.put("" + xValue, yValue);
        }
      }

      // Finally the JFreeChart data object is created and filled with the processed data
      // DefaultKeyedValues data = new DefaultKeyedValues();
      for (int i = 1; i <= TOP_VALUE; i++) {
        String category = "" + i;
        int value = map.containsKey(category) ? map.get(category) : 0;
        dataset.addValue(value, serieKey, category);
      }
      dataset.addValue(greaterThanTopValue, serieKey, GT_TOP_VALUE_KEY);
      seriesColor.add(seriesType.getColor());
    }

    chart =
        ChartFactory.createBarChart(
            getChartTitle(), // chart title
            "Precursor Ion Charge", // x axis label
            "Frequency", // y axis label
            dataset, // chartData
            PlotOrientation.VERTICAL,
            true, // include legend
            true, // tooltips
            false // urls
            );
    chart.addSubtitle(new TextTitle());

    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setBaseItemLabelGenerator(new NumberLegendGenerator());
    for (int i = 0; i < dataset.getRowCount(); i++) {
      renderer.setSeriesItemLabelsVisible(i, Boolean.TRUE);
      renderer.setSeriesPaint(i, seriesColor.get(i));
    }

    plot.getRangeAxis().setUpperMargin(CHART_UPPER_MARGIN);
    plot.setBackgroundAlpha(0f);
    plot.setDomainGridlinePaint(Color.red);
    plot.setRangeGridlinePaint(Color.blue);

    renderer.setShadowVisible(false);
    renderer.setDrawBarOutline(false);
    renderer.setItemMargin(0);
  }