Java Code Examples for org.jfree.chart.plot.XYPlot#getDatasetCount()

The following examples show how to use org.jfree.chart.plot.XYPlot#getDatasetCount() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VariablePlot.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void clear() {
  XYPlot p = chart.getXYPlot();

  for (int i = 0; i < p.getDatasetCount(); i++) {
    Dataset dataset = p.getDataset(i);

    log.info("clear dataset " + i + " dataset " + dataset);

    if (dataset instanceof TimeSeriesCollection)
      ((TimeSeriesCollection) dataset).removeAllSeries();
    if (dataset instanceof XYSeriesCollection)
      ((XYSeriesCollection) dataset).removeAllSeries();

    p.setDataset(i, null);
    if (i > 0)
      p.setRangeAxis(i, null);
  }
}
 
Example 2
Source File: ChartJFreeChartOutputScatter.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void clearDataSet(final IScope scope) {
	// TODO Auto-generated method stub
	super.clearDataSet(scope);
	final XYPlot plot = (XYPlot) this.chart.getPlot();
	for (int i = plot.getDatasetCount() - 1; i >= 1; i--) {
		plot.setDataset(i, null);
		plot.setRenderer(i, null);
	}
	((XYIntervalSeriesCollection) jfreedataset.get(0)).removeAllSeries();
	jfreedataset.clear();
	jfreedataset.add(0, new XYIntervalSeriesCollection());
	plot.setDataset((XYIntervalSeriesCollection) jfreedataset.get(0));
	plot.setRenderer(0, null);
	IdPosition.clear();
}
 
Example 3
Source File: ChartJFreeChartOutputHeatmap.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void clearDataSet(final IScope scope) {
	// TODO Auto-generated method stub
	super.clearDataSet(scope);
	final XYPlot plot = (XYPlot) this.chart.getPlot();
	for (int i = plot.getDatasetCount() - 1; i >= 1; i--) {
		plot.setDataset(i, null);
		plot.setRenderer(i, null);
	}
	((MatrixSeriesCollection) jfreedataset.get(0)).removeAllSeries();
	jfreedataset.clear();
	jfreedataset.add(0, new MatrixSeriesCollection());
	plot.setDataset((MatrixSeriesCollection) jfreedataset.get(0));
	plot.setRenderer(0, null);

	IdPosition.clear();
}
 
Example 4
Source File: JFreeChartPlotEngine.java    From rapidminer-studio with GNU Affero General Public License v3.0 5 votes vote down vote up
private void pushDataAndRendererIntoPlot(XYPlot plot, int rangeAxisIdx, XYItemRenderer renderer, XYDataset dataset)
		throws ChartPlottimeException {
	if (dataset != null && renderer != null) {
		int datasetIdx = plot.getDatasetCount();
		if (datasetIdx > 0 && plot.getDataset(datasetIdx - 1) == null) {
			datasetIdx -= 1;
		}
		// push dataset and renderer into plot
		try {
			plot.setDataset(datasetIdx, dataset); // if Eclipse states that
													 // dataset might not be
													 // initialized, you did
													 // not consider all
													 // possibilities in the
													 // condition block above
		} catch (RuntimeException e) {
			// probably this is because the domain axis contains values less
			// then zero and the scaling is logarithmic.
			// The shitty JFreeChart implementation does not throw a proper
			// exception stating what happened,
			// but just a RuntimeException with a string, so this is our
			// best guess:
			if (isProbablyZeroValuesOnLogScaleException(e)) {
				throw new ChartPlottimeException("gui.plotter.error.log_axis_contains_zero", "domain axis");
			} else {
				throw e;
			}
		}
		plot.mapDatasetToRangeAxis(datasetIdx, rangeAxisIdx);
		plot.setRenderer(datasetIdx, renderer);
	} else {
		ChartPlottimeException chartPlottimeException = new ChartPlottimeException(
				new PlotConfigurationError("generic_plotter_error"));
		throw chartPlottimeException;
	}
}
 
Example 5
Source File: DSWorkbenchStatsFrame.java    From dsworkbench with Apache License 2.0 5 votes vote down vote up
private void setupChart(String pInitialId, XYDataset pInitialDataset) {
    chart = ChartFactory.createTimeSeriesChart(
            "Spielerstatistiken", // title
            "Zeiten", // x-axis label
            pInitialId, // y-axis label
            pInitialDataset, // data
            jShowLegend.isSelected(), // create legend?
            true, // generate tooltips?
            false // generate URLs?
            );
    
    chart.setBackgroundPaint(Constants.DS_BACK);
    XYPlot plot = (XYPlot) chart.getPlot();
    setupPlotDrawing(plot);
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    for (int i = 0; i < plot.getSeriesCount(); i++) {
        renderer.setSeriesLinesVisible(i, jShowLines.isSelected());
        renderer.setSeriesShapesVisible(i, jShowDataPoints.isSelected());
        plot.setRenderer(i, renderer);
    }
    
    renderer.setDefaultItemLabelsVisible(jShowItemValues.isSelected());
    renderer.setDefaultItemLabelGenerator(new org.jfree.chart.labels.StandardXYItemLabelGenerator());
    renderer.setDefaultToolTipGenerator(new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, new SimpleDateFormat("dd.MM.yyyy HH:mm:ss"), NumberFormat.getInstance()));
    int lastDataset = plot.getDatasetCount() - 1;
    if (lastDataset > 0) {
        plot.getRangeAxis().setAxisLinePaint(plot.getLegendItems().get(lastDataset).getLinePaint());
        plot.getRangeAxis().setLabelPaint(plot.getLegendItems().get(lastDataset).getLinePaint());
        plot.getRangeAxis().setTickLabelPaint(plot.getLegendItems().get(lastDataset).getLinePaint());
        plot.getRangeAxis().setTickMarkPaint(plot.getLegendItems().get(lastDataset).getLinePaint());
    }
    NumberFormat nf = NumberFormat.getInstance();
    nf.setMinimumFractionDigits(0);
    nf.setMaximumFractionDigits(0);
    NumberAxis na = ((NumberAxis) plot.getRangeAxis());
    if (na != null) {
        na.setNumberFormatOverride(nf);
    }
}
 
Example 6
Source File: GraphPanel.java    From swift-k with Apache License 2.0 5 votes vote down vote up
private int getNextDatasetIndex(XYPlot plot) {
    for (int i = 0; i < plot.getDatasetCount(); i++) {
        if (plot.getDataset(i) == null) {
            return i;
        }
    }
    return plot.getDatasetCount();
}
 
Example 7
Source File: MetadataPlotTableModel.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
MetadataPlotTableModel(XYPlot plot) {
    this.plot = plot;
    columList = new ArrayList<>();
    columList.add(plot.getDomainAxis().getLabel());
    for(int i = 0; i < plot.getDatasetCount(); i++) {
        columList.add(String.valueOf(plot.getDataset(i).getSeriesKey(0)));
    }
}
 
Example 8
Source File: ReportGenerator.java    From nmonvisualizer with Apache License 2.0 5 votes vote down vote up
private boolean chartHasData(JFreeChart chart) {
    boolean hasData = false;

    // determine if there will really be any data to display
    // do not output a chart if there is no data
    Plot plot = chart.getPlot();

    if (plot instanceof CategoryPlot) {
        CategoryPlot cPlot = (CategoryPlot) plot;

        outer: for (int i = 0; i < cPlot.getDatasetCount(); i++) {
            for (int j = 0; j < cPlot.getDataset(i).getRowCount(); j++) {
                for (int k = 0; k < cPlot.getDataset(i).getColumnCount(); k++) {
                    Number value = cPlot.getDataset(0).getValue(j, k);

                    if ((value != null) && !Double.isNaN(value.doubleValue())) {
                        hasData = true;
                        break outer;
                    }
                }
            }

        }
    }
    else if (plot instanceof XYPlot) {
        XYPlot xyPlot = (XYPlot) plot;

        for (int i = 0; i < xyPlot.getDatasetCount(); i++) {
            if (xyPlot.getDataset(i).getSeriesCount() > 0) {
                hasData = true;
                break;
            }
        }
    }
    else {
        System.err.println("unknown plot type " + plot.getClass() + " for chart " + chart.getTitle());
    }

    return hasData;
}
 
Example 9
Source File: HistogramPanel.java    From mzmine3 with GNU General Public License v2.0 4 votes vote down vote up
protected void hideGaussianCurve(XYPlot p) {
  if (p.getDatasetCount() > 1) {
    p.setRenderer(p.getDatasetCount() - 1, null);
    p.setDataset(p.getDatasetCount() - 1, null);
  }
}
 
Example 10
Source File: IntelligentItemLabelGenerator.java    From old-mzmine3 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * @see org.jfree.chart.labels.XYItemLabelGenerator#generateLabel(org.jfree.data.xy.XYDataset,
 *      int, int)
 */
public String generateLabel(XYDataset currentDataset, int currentSeries, int currentItem) {

  XYPlot plot = chartNode.getChart().getXYPlot();

  // X and Y values of the current data point
  final double currentXValue = currentDataset.getXValue(currentSeries, currentItem);
  final double currentYValue = currentDataset.getYValue(currentSeries, currentItem);

  // Calculate X axis span of 1 screen pixel
  final double xLength = plot.getDomainAxis().getRange().getLength();
  final double pixelX = xLength / chartNode.getWidth();

  // Calculate the distance from the current point where labels might
  // overlap
  final double dangerZoneX = (reservedPixels / 2) * pixelX;

  // Range on X axis that we're going to check for higher data points. If
  // a higher data point is found, we don't place a label on this one.
  final Range<Double> dangerZoneRange =
      Range.closed(currentXValue - dangerZoneX, currentXValue + dangerZoneX);

  // Iterate through data sets
  for (int datasetIndex = 0; datasetIndex < plot.getDatasetCount(); datasetIndex++) {

    XYDataset dataset = plot.getDataset(datasetIndex);

    // Some data sets could have been removed
    if (dataset == null)
      continue;

    final int seriesCount = dataset.getSeriesCount();

    // Iterate through series
    for (int seriesIndex = 0; seriesIndex < seriesCount; seriesIndex++) {

      final int itemCount = dataset.getItemCount(seriesIndex);

      // Find the index of a data point that is closest to
      // currentXValue
      int closestValueIndex;
      if (dataset == currentDataset && seriesIndex == currentSeries) {
        closestValueIndex = currentItem;
      } else {
        closestValueIndex =
            findClosestXIndex(dataset, seriesIndex, currentXValue, 0, itemCount - 1);
      }

      // Search to the left of the closest data point
      for (int i = closestValueIndex; (i >= 0)
          && (dangerZoneRange.contains(dataset.getX(seriesIndex, i).doubleValue())); i--) {
        if (dataset.getYValue(seriesIndex, i) > currentYValue)
          return null;

        // In the case there are equal values, only place the label
        // on the leftmost value
        if (dataset.getYValue(seriesIndex, i) == currentYValue
            && (dataset.getXValue(seriesIndex, i) < currentXValue))
          return null;

      }

      // Search to the right of the closest data point
      for (int i = closestValueIndex + 1; (i < itemCount)
          && (dangerZoneRange.contains(dataset.getX(seriesIndex, i).doubleValue())); i++) {
        if (dataset.getYValue(seriesIndex, i) > currentYValue)
          return null;
      }

    }

  }

  // If no higher data point was found, create the label
  String label = underlyingGenerator.generateLabel(currentDataset, currentSeries, currentItem);

  return label;

}
 
Example 11
Source File: HistogramPanel.java    From mzmine2 with GNU General Public License v2.0 4 votes vote down vote up
protected void hideGaussianCurve(XYPlot p) {
  if (p.getDatasetCount() > 1) {
    p.setRenderer(p.getDatasetCount() - 1, null);
    p.setDataset(p.getDatasetCount() - 1, null);
  }
}