double total = DatasetUtilities.calculatePieDatasetTotal(dataset); result[0] = key.toString(); Number value = dataset.getValue(key);
/** * Creates a new pie dataset based on the supplied dataset, but modified * by aggregating all the low value items (those whose value is lower * than the <code>percentThreshold</code>) into a single item with the * key "Other". * * @param source the source dataset (<code>null</code> not permitted). * @param key a new key for the aggregated items (<code>null</code> not * permitted). * @param minimumPercent the percent threshold. * * @return The pie dataset with (possibly) aggregated items. */ public static PieDataset createConsolidatedPieDataset(PieDataset source, Comparable key, double minimumPercent) { return DatasetUtilities.createConsolidatedPieDataset(source, key, minimumPercent, 2); }
/** * Creates an {@link XYDataset} by sampling the specified function over a * fixed range. * * @param f the function (<code>null</code> not permitted). * @param start the start value for the range. * @param end the end value for the range. * @param samples the number of sample points (must be > 1). * @param seriesKey the key to give the resulting series * (<code>null</code> not permitted). * * @return A dataset. */ public static XYDataset sampleFunction2D(Function2D f, double start, double end, int samples, Comparable seriesKey) { // defer argument checking XYSeries series = sampleFunction2DToSeries(f, start, end, samples, seriesKey); XYSeriesCollection collection = new XYSeriesCollection(series); return collection; }
/** * Returns the range for an axis. * * @param axis the axis. * * @return The range for an axis. */ public Range getDataRange(ValueAxis axis) { if (this.dataset == null) { return null; } Range result = null; if (axis == getDomainAxis()) { result = DatasetUtilities.findDomainBounds(this.dataset); } else if (axis == getRangeAxis()) { result = DatasetUtilities.findRangeBounds(this.dataset); } return result; }
if (DatasetUtilities.isEmptyOrNull(this.dataset)) { drawNoDataMessage(g2, area); return; this.dataExtractOrder, pieIndex); if (this.limit > 0.0) { piedataset = DatasetUtilities.createConsolidatedPieDataset( dd, this.aggregatedItemsKey, this.limit);
if (DatasetUtilities.isEmptyOrNull(getDataset())) { drawNoDataMessage(g2, plotArea); g2.setClip(savedClip); getForegroundAlpha())); double totalValue = DatasetUtilities.calculatePieDatasetTotal(dataset); double runningTotal = 0; if (depth < 0) {
/** * Returns <code>true</code> if all the datasets belonging to the specified * plot are empty or <code>null</code>, and <code>false</code> otherwise. * * @param plot the plot (<code>null</code> permitted). * * @return A boolean. * * @since 1.0.7 */ public static boolean isEmptyOrNull(XYPlot plot) { if (plot != null) { for (int i = 0, n = plot.getDatasetCount(); i < n; i++) { final XYDataset dataset = plot.getDataset(i); if (!DatasetUtilities.isEmptyOrNull(dataset)) { return false; } } } return true; }
/** * Creates a pie dataset from a table dataset by taking all the values * for a single row. * * @param dataset the dataset (<code>null</code> not permitted). * @param rowKey the row key. * * @return A pie dataset. */ public static PieDataset createPieDatasetForRow(CategoryDataset dataset, Comparable rowKey) { int row = dataset.getRowIndex(rowKey); return createPieDatasetForRow(dataset, row); }
/** * Returns the range of values in the domain (x-values) of a dataset. * * @param dataset the dataset (<code>null</code> not permitted). * * @return The range of values (possibly <code>null</code>). */ public static Range findDomainBounds(XYDataset dataset) { return findDomainBounds(dataset, true); }
public static final CategoryDataset createCategoryDataset( SpreadSheet sheet, int rowSize, int columnSize) { double[][] data = new double[rowSize][columnSize]; Comparable[] rowKeys = new Comparable[rowSize]; Comparable[] columnKeys = new Comparable[columnSize]; List rowHeaders = sheet.getRowHeaders(); List columnHeaders = sheet.getColumnHeaders(); for (int row = 0; row < rowSize; row++) { rowKeys[row] = (Comparable) rowHeaders.get(row); DataRow dataRow = sheet.nextRow(); for (int column = 0; column < columnSize; column++) { if (row == 0) { columnKeys[column] = (Comparable) columnHeaders.get(column); } Object obj = dataRow.next(); if (obj != null) { data[row][column] = Double.parseDouble(String.valueOf(obj)); } else { data[row][column] = 0.0; } } } return DatasetUtilities .createCategoryDataset(rowKeys, columnKeys, data); }
/** * Creates a pie dataset from a table dataset by taking all the values * for a single column. * * @param dataset the dataset (<code>null</code> not permitted). * @param columnKey the column key. * * @return A pie dataset. */ public static PieDataset createPieDatasetForColumn(CategoryDataset dataset, Comparable columnKey) { int column = dataset.getColumnIndex(columnKey); return createPieDatasetForColumn(dataset, column); }
total = DatasetUtilities.calculateStackTotal( (TableXYDataset) dataset, item); value = value / total;
if(DatasetUtilities.isEmptyOrNull(getDataset())) if(getLimit() > 0.0) piedataset = DatasetUtilities.createConsolidatedPieDataset(dd, getAggregatedItemsKey(), getLimit());
/** * Draws a representation of the data within the dataArea region, using the * current m_Renderer. * * @param g2 the graphics device. * @param dataArea the region in which the data is to be drawn. * @param info an optional object for collection dimension * information (<code>null</code> permitted). */ protected void render(Graphics2D g2, Rectangle2D dataArea, PlotRenderingInfo info) { // now get the data and plot it (the visual representation will depend // on the m_Renderer that has been set)... if (!DatasetUtilities.isEmptyOrNull(this.dataset)) { int seriesCount = this.dataset.getSeriesCount(); for (int series = 0; series < seriesCount; series++) { this.renderer.drawSeries(g2, dataArea, info, this, this.dataset, series); } } else { drawNoDataMessage(g2, dataArea); } }
public static final JFreeChart createPieChart(DataTable dataTable) { int columnSize = dataTable.getColumnSize(); JFreeChart pieChart = null; if (columnSize == 2) { CategoryDataset cData = createCategoryDataset(dataTable); PieDataset pieData = DatasetUtilities.createPieDatasetForRow(cData, 0); pieChart = ChartFactory.createPieChart(dataTable.getName(), pieData, true, true, true); // PiePlot piePlot = (PiePlot) pieChart.getPlot(); // piePlot.setCircular(false); // piePlot.setExplodePercent(1, 0.5); } return pieChart; }
DatasetUtilities.findDomainBounds(d)); DatasetUtilities.findRangeBounds(d));
/** * Returns the range required by this renderer to display all the domain * values in the specified dataset. * * @param dataset the dataset (<code>null</code> permitted). * * @return The range, or <code>null</code> if the dataset is * <code>null</code>. */ public Range findDomainBounds(XYDataset dataset) { if (dataset != null) { return DatasetUtilities.findDomainBounds(dataset, true); } else { return null; } }
public static final CategoryDataset createCategoryDataset( DataTable dataTable, int rowSize) { double[][] data = new double[1][rowSize]; Comparable[] rowKeys = new Comparable[1]; Comparable[] columnKeys = new Comparable[rowSize]; rowKeys[0] = (String)dataTable.getHeaders().get(1); for (int i = 0; dataTable.hasNextRow(); i++) { DataRow dataRow = dataTable.nextRow(); Comparable columnKey = (Comparable) dataRow.getCell(0); if(columnKey == null){ columnKey = TgwResource.getMessage("msg.nodata"); } columnKeys[i] = columnKey; Object obj = dataRow.getCell(1); if (obj != null) { data[0][i] = Double.parseDouble(String.valueOf(obj)); } else { data[0][i] = 0.0; } } return DatasetUtilities .createCategoryDataset(rowKeys, columnKeys, data); }
double total = DatasetUtilities.calculatePieDatasetTotal(dataset);
private XYIntervalSeries computeRegressionData(double xStart, double xEnd) { if (scatterpointsDataset.getItemCount(0) > 1) { final double[] coefficients = Regression.getOLSRegression(scatterpointsDataset, 0); final Function2D curve = new LineFunction2D(coefficients[0], coefficients[1]); final XYSeries regressionData = DatasetUtilities.sampleFunction2DToSeries( curve, xStart, xEnd, 100, "regression line"); final XYIntervalSeries xyIntervalRegression = new XYIntervalSeries(regressionData.getKey()); final List<XYDataItem> regressionDataItems = regressionData.getItems(); for (XYDataItem item : regressionDataItems) { final double x = item.getXValue(); final double y = item.getYValue(); xyIntervalRegression.add(x, x, x, y, y, y); } return xyIntervalRegression; } else { JOptionPane.showMessageDialog(this, "Unable to compute regression line.\n" + "At least 2 values are needed to compute regression coefficients."); return null; } }