XYPlot plot = chart.getXYPlot(); plot.setDataset(0, xyDataset1); plot.setDataset(1, xyDataset2); XYLineAndShapeRenderer renderer0 = new XYLineAndShapeRenderer(); XYLineAndShapeRenderer renderer1 = new XYLineAndShapeRenderer(); plot.setRenderer(0, renderer0); plot.setRenderer(1, renderer1); plot.getRendererForDataset(plot.getDataset(0)).setSeriesPaint(0, Color.red); plot.getRendererForDataset(plot.getDataset(1)).setSeriesPaint(0, Color.blue);
/** * Gets the index of the first dataset containing the specified series. * * @param aPlot Plot to be searched for the dataset of the fitted function. * @param aSeriesName Name of series the dataset should contain. * @return Index of the dataset which contains series named <code>aSeriesName</code>, * <code>-1</code> if such dataset does not exist. */ protected static int getDatasetIndex(XYPlot aPlot, String aSeriesName) { final int datasetCount = aPlot.getDatasetCount(); for (int i = 0; i < datasetCount; ++i) { if (aSeriesName.equals(aPlot.getDataset(i).getSeriesKey(0))) { return i; } } return -1; }
/** * Returns the primary dataset for the plot. * * @return The primary dataset (possibly {@code null}). * * @see #getDataset(int) * @see #setDataset(XYDataset) */ public XYDataset getDataset() { return getDataset(0); }
public static XYPlot addDatasetRender(XYPlot plot, XYDataset dataset, XYItemRenderer renderer) { int index = plot.getDatasetCount(); // Bug jfreechart. When we create a XYPlot without dataset, one null dataset is added to list. if (index == 1 && plot.getDataset(0) == null) { index--; } plot.setDataset(index, dataset); plot.setRenderer(index, renderer); return plot; }
/** * Returns the primary dataset for the plot. * * @return The primary dataset (possibly <code>null</code>). * * @see #getDataset(int) * @see #setDataset(XYDataset) */ public XYDataset getDataset() { return getDataset(0); }
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))); } }
/** * Returns the number of series in the primary dataset for this plot. If * the dataset is {@code null}, the method returns 0. * * @return The series count. */ public int getSeriesCount() { int result = 0; XYDataset dataset = getDataset(); if (dataset != null) { result = dataset.getSeriesCount(); } return result; }
@Override public int getRowCount() { return plot.getDataset().getItemCount(0); }
private boolean hasDiagram() { return chart.getXYPlot().getDataset() != null; }
/** * Returns the number of series in the primary dataset for this plot. If * the dataset is <code>null</code>, the method returns 0. * * @return The series count. */ public int getSeriesCount() { int result = 0; XYDataset dataset = getDataset(); if (dataset != null) { result = dataset.getSeriesCount(); } return result; }
private XYSeries getXYSeries(PixExOp.VariableCombination variableCombination, long productId) { final XYSeries xySeries; if (plotMaps.get(productId).containsKey(variableCombination)) { xySeries = ((XYSeriesCollection) plotMaps.get(productId).get(variableCombination).getXYPlot().getDataset()).getSeries(0); } else { xySeries = new XYSeries("data"); JFreeChart scatterPlot = createScatterPlot(variableCombination, xySeries, productId); plotMaps.get(productId).put(variableCombination, scatterPlot); } return xySeries; }
@Override public Object getValueAt(int rowIndex, int columnIndex) { if (columnIndex == 0) { return plot.getDataset(columnIndex).getXValue(0, rowIndex); } else { XYDataset dataset = plot.getDataset(columnIndex - 1); int itemCount = dataset.getItemCount(0); if (rowIndex < itemCount) { return dataset.getYValue(0, rowIndex); }else { return null; } } }
private XYSeriesCollection getCategory() { return (XYSeriesCollection) panel.getChart().getXYPlot().getDataset(); }
/** * Maps the specified dataset to the axes in the list. Note that the * conversion of data values into Java2D space is always performed using * the first axis in the list. * * @param index the dataset index (zero-based). * @param axisIndices the axis indices ({@code null} permitted). * * @since 1.0.12 */ public void mapDatasetToDomainAxes(int index, List axisIndices) { Args.requireNonNegative(index, "index"); checkAxisIndices(axisIndices); Integer key = new Integer(index); this.datasetToDomainAxesMap.put(key, new ArrayList(axisIndices)); // fake a dataset change event to update axes... datasetChanged(new DatasetChangeEvent(this, getDataset(index))); }
/** * Maps the specified dataset to the axes in the list. Note that the * conversion of data values into Java2D space is always performed using * the first axis in the list. * * @param index the dataset index (zero-based). * @param axisIndices the axis indices ({@code null} permitted). * * @since 1.0.12 */ public void mapDatasetToRangeAxes(int index, List axisIndices) { Args.requireNonNegative(index, "index"); checkAxisIndices(axisIndices); Integer key = new Integer(index); this.datasetToRangeAxesMap.put(key, new ArrayList(axisIndices)); // fake a dataset change event to update axes... datasetChanged(new DatasetChangeEvent(this, getDataset(index))); }
/** * Updates the series name at the specified index * @param seriesName the new seriesName to set at the specified index * @param index the desired index to set the new seriesName to */ public void updateSeriesNameAt(String seriesName, int index) { if (!lock) { XYSeries s = ((XYSeriesCollection) chart.getXYPlot().getDataset()).getSeries(index); s.setKey(seriesName); } }
/** * Extracts the visualized data from a given chart instance. * <p> * This methods extracts the default data series from the default dataset of the given chart. * </p> * * @param aChart * Chart to extract the data from. * @return Visualized data in the form of an array of points. */ public static Point2D.Double[] extractData(JFreeChart aChart) { XYDataset dataColl = aChart.getXYPlot().getDataset(); final int n = dataColl.getItemCount(0); Point2D.Double[] dataPoints = new Point2D.Double[n]; for (int i = 0; i < n; ++i) { dataPoints[i] = new Point2D.Double(dataColl.getXValue(0, i), dataColl.getYValue(0, i)); } return dataPoints; }
/** * Updates the values for the specified seriesName with the given values * @param seriesName the name a series in the graph * @param index the index of the desired series to update * @param time the time at which to update * @param value the value to update */ public void updateValues(String seriesName, int index, double time, double value) { if (!lock) { XYSeries s = ((XYSeriesCollection) chart.getXYPlot().getDataset()).getSeries(index); s.setKey(seriesName); s.addOrUpdate(time, value); } }
/** * Clear the graph starting from the startTime. * @param startTime an x-value on the graph */ public void clearValues(int index, double startTime) { if (!lock) { XYSeries s = ((XYSeriesCollection) chart.getXYPlot().getDataset()).getSeries(index); int i = s.indexOf(startTime); if (i >= 0) { int total = s.getItemCount(); for (; i < total; total--) { s.remove(i); } } } }
/** * Clears all values for all series, leaving the same number of series */ public void clearValues() { if (!lock) { for (int i = 0; i < chart.getXYPlot().getSeriesCount(); i++) { XYSeries s = ((XYSeriesCollection) chart.getXYPlot().getDataset()).getSeries(i); while (s.getItemCount() > 0) { s.remove(0); } } } }