List of usage examples for org.jfree.data.category CategoryDataset getValue
public Number getValue(Comparable rowKey, Comparable columnKey);
From source file:KIDLYRenderer.java
/** * Draws the bar for a single (series, category) data item. * * @param g2 the graphics device./*from w ww . jav a 2 s. c o m*/ * @param state the renderer state. * @param dataArea the data area. * @param plot the plot. * @param domainAxis the domain axis. * @param rangeAxis the range axis. * @param dataset the dataset. * @param row the row index (zero-based). * @param column the column index (zero-based). * @param pass the pass index. */ public void drawItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int row, int column, int pass) { // nothing is drawn if the row index is not included in the list with // the indices of the visible rows... int visibleRow = state.getVisibleSeriesIndex(row); if (visibleRow < 0) { return; } // nothing is drawn for null values... Number dataValue = dataset.getValue(row, column); if (dataValue == null) { return; } final double value = dataValue.doubleValue(); PlotOrientation orientation = plot.getOrientation(); double barW0 = calculateBarW0(plot, orientation, dataArea, domainAxis, state, visibleRow, column); double[] barL0L1 = calculateBarL0L1(value); if (barL0L1 == null) { return; // the bar is not visible } RectangleEdge edge = plot.getRangeAxisEdge(); double transL0 = rangeAxis.valueToJava2D(barL0L1[0], dataArea, edge); double transL1 = rangeAxis.valueToJava2D(barL0L1[1], dataArea, edge); // in the following code, barL0 is (in Java2D coordinates) the LEFT // end of the bar for a horizontal bar chart, and the TOP end of the // bar for a vertical bar chart. Whether this is the BASE of the bar // or not depends also on (a) whether the data value is 'negative' // relative to the base value and (b) whether or not the range axis is // inverted. This only matters if/when we apply the minimumBarLength // attribute, because we should extend the non-base end of the bar boolean positive = (value >= this.base); boolean inverted = rangeAxis.isInverted(); double barL0 = Math.min(transL0, transL1); double barLength = Math.abs(transL1 - transL0); double barLengthAdj = 0.0; if (barLength > 0.0 && barLength < getMinimumBarLength()) { barLengthAdj = getMinimumBarLength() - barLength; } double barL0Adj = 0.0; RectangleEdge barBase; if (orientation == PlotOrientation.HORIZONTAL) { if (positive && inverted || !positive && !inverted) { barL0Adj = barLengthAdj; barBase = RectangleEdge.RIGHT; } else { barBase = RectangleEdge.LEFT; } } else { if (positive && !inverted || !positive && inverted) { barL0Adj = barLengthAdj; barBase = RectangleEdge.BOTTOM; } else { barBase = RectangleEdge.TOP; } } // draw the bar... Rectangle2D bar = null; if (orientation == PlotOrientation.HORIZONTAL) { bar = new Rectangle2D.Double(barL0 - barL0Adj, barW0, barLength + barLengthAdj, state.getBarWidth()); } else { bar = new Rectangle2D.Double(barW0, barL0 - barL0Adj, state.getBarWidth(), barLength + barLengthAdj); } /* if (getShadowsVisible()) { this.barPainter.paintBarShadow(g2, this, row, column, bar, barBase, true); } this.barPainter.paintBar(g2, this, row, column, bar, barBase);*/ CategoryItemLabelGenerator generator = getItemLabelGenerator(row, column); if (generator != null && isItemLabelVisible(row, column)) { drawItemLabel(g2, dataset, row, column, plot, generator, bar, (value < 0.0)); } // submit the current data point as a crosshair candidate int datasetIndex = plot.indexOf(dataset); updateCrosshairValues(state.getCrosshairState(), dataset.getRowKey(row), dataset.getColumnKey(column), value, datasetIndex, barW0, barL0, orientation); // add an item entity, if this information is being collected EntityCollection entities = state.getEntityCollection(); if (entities != null) { addItemEntity(entities, dataset, row, column, bar); } }
From source file:org.jfree.data.general.DatasetUtilities.java
/** * Returns the maximum value in the dataset range, assuming that values in * each category are "stacked"./* ww w. jav a 2s . co m*/ * * @param dataset the dataset (<code>null</code> not permitted). * * @return The maximum value (possibly <code>null</code>). * * @see #findMinimumStackedRangeValue(CategoryDataset) */ public static Number findMaximumStackedRangeValue(CategoryDataset dataset) { ParamChecks.nullNotPermitted(dataset, "dataset"); Number result = null; boolean hasValidData = false; double maximum = 0.0; int categoryCount = dataset.getColumnCount(); for (int item = 0; item < categoryCount; item++) { double total = 0.0; int seriesCount = dataset.getRowCount(); for (int series = 0; series < seriesCount; series++) { Number number = dataset.getValue(series, item); if (number != null) { hasValidData = true; double value = number.doubleValue(); if (value > 0.0) { total = total + value; } } } maximum = Math.max(maximum, total); } if (hasValidData) { result = new Double(maximum); } return result; }
From source file:org.jfree.data.general.DatasetUtilities.java
/** * Returns the minimum value in the dataset range, assuming that values in * each category are "stacked"./*from ww w . jav a2 s . c om*/ * * @param dataset the dataset (<code>null</code> not permitted). * * @return The minimum value. * * @see #findMaximumStackedRangeValue(CategoryDataset) */ public static Number findMinimumStackedRangeValue(CategoryDataset dataset) { ParamChecks.nullNotPermitted(dataset, "dataset"); Number result = null; boolean hasValidData = false; double minimum = 0.0; int categoryCount = dataset.getColumnCount(); for (int item = 0; item < categoryCount; item++) { double total = 0.0; int seriesCount = dataset.getRowCount(); for (int series = 0; series < seriesCount; series++) { Number number = dataset.getValue(series, item); if (number != null) { hasValidData = true; double value = number.doubleValue(); if (value < 0.0) { total = total + value; // '+', remember value is negative } } } minimum = Math.min(minimum, total); } if (hasValidData) { result = new Double(minimum); } return result; }
From source file:org.jfree.data.general.DatasetUtils.java
/** * Calculates the range of values for a dataset where each item is the * running total of the items for the current series. * * @param dataset the dataset ({@code null} not permitted). * * @return The range./*w w w . jav a2 s. c om*/ * * @see #findRangeBounds(CategoryDataset) */ public static Range findCumulativeRangeBounds(CategoryDataset dataset) { Args.nullNotPermitted(dataset, "dataset"); boolean allItemsNull = true; // we'll set this to false if there is at // least one non-null data item... double minimum = 0.0; double maximum = 0.0; for (int row = 0; row < dataset.getRowCount(); row++) { double runningTotal = 0.0; for (int column = 0; column <= dataset.getColumnCount() - 1; column++) { Number n = dataset.getValue(row, column); if (n != null) { allItemsNull = false; double value = n.doubleValue(); if (!Double.isNaN(value)) { runningTotal = runningTotal + value; minimum = Math.min(minimum, runningTotal); maximum = Math.max(maximum, runningTotal); } } } } if (!allItemsNull) { return new Range(minimum, maximum); } else { return null; } }
From source file:org.jfree.data.general.DatasetUtilities.java
/** * Calculates the range of values for a dataset where each item is the * running total of the items for the current series. * * @param dataset the dataset (<code>null</code> not permitted). * * @return The range./*from w w w . j a v a 2s . c o m*/ * * @see #findRangeBounds(CategoryDataset) */ public static Range findCumulativeRangeBounds(CategoryDataset dataset) { ParamChecks.nullNotPermitted(dataset, "dataset"); boolean allItemsNull = true; // we'll set this to false if there is at // least one non-null data item... double minimum = 0.0; double maximum = 0.0; for (int row = 0; row < dataset.getRowCount(); row++) { double runningTotal = 0.0; for (int column = 0; column <= dataset.getColumnCount() - 1; column++) { Number n = dataset.getValue(row, column); if (n != null) { allItemsNull = false; double value = n.doubleValue(); if (!Double.isNaN(value)) { runningTotal = runningTotal + value; minimum = Math.min(minimum, runningTotal); maximum = Math.max(maximum, runningTotal); } } } } if (!allItemsNull) { return new Range(minimum, maximum); } else { return null; } }
From source file:org.jfree.data.general.DatasetUtils.java
/** * Returns the minimum and maximum values for the dataset's range * (y-values), assuming that the series in one category are stacked. * * @param dataset the dataset ({@code null} not permitted). * @param base the base value for the bars. * * @return The range ({@code null} if the dataset contains no values). *///from w w w . jav a2s . c om public static Range findStackedRangeBounds(CategoryDataset dataset, double base) { Args.nullNotPermitted(dataset, "dataset"); Range result = null; double minimum = Double.POSITIVE_INFINITY; double maximum = Double.NEGATIVE_INFINITY; int categoryCount = dataset.getColumnCount(); for (int item = 0; item < categoryCount; item++) { double positive = base; double negative = base; int seriesCount = dataset.getRowCount(); for (int series = 0; series < seriesCount; series++) { Number number = dataset.getValue(series, item); if (number != null) { double value = number.doubleValue(); if (value > 0.0) { positive = positive + value; } if (value < 0.0) { negative = negative + value; // '+', remember value is negative } } } minimum = Math.min(minimum, negative); maximum = Math.max(maximum, positive); } if (minimum <= maximum) { result = new Range(minimum, maximum); } return result; }
From source file:org.jfree.data.general.DatasetUtilities.java
/** * Returns the minimum and maximum values for the dataset's range * (y-values), assuming that the series in one category are stacked. * * @param dataset the dataset (<code>null</code> not permitted). * @param base the base value for the bars. * * @return The range (<code>null</code> if the dataset contains no values). *//*from w w w .j a v a2s. co m*/ public static Range findStackedRangeBounds(CategoryDataset dataset, double base) { ParamChecks.nullNotPermitted(dataset, "dataset"); Range result = null; double minimum = Double.POSITIVE_INFINITY; double maximum = Double.NEGATIVE_INFINITY; int categoryCount = dataset.getColumnCount(); for (int item = 0; item < categoryCount; item++) { double positive = base; double negative = base; int seriesCount = dataset.getRowCount(); for (int series = 0; series < seriesCount; series++) { Number number = dataset.getValue(series, item); if (number != null) { double value = number.doubleValue(); if (value > 0.0) { positive = positive + value; } if (value < 0.0) { negative = negative + value; // '+', remember value is negative } } } minimum = Math.min(minimum, negative); maximum = Math.max(maximum, positive); } if (minimum <= maximum) { result = new Range(minimum, maximum); } return result; }
From source file:it.eng.spagobi.engines.chart.bo.charttypes.utils.MyCategoryToolTipGenerator.java
public String generateToolTip(CategoryDataset dataset, int row, int column) { logger.debug("IN"); //String tooltip=super.generateToolTip(dataset, row, column); String rowName = ""; String columnName = ""; try {/*from ww w .j a v a 2 s. com*/ Comparable rowNameC = (String) dataset.getRowKey(row); Comparable columnNameC = (String) dataset.getColumnKey(column); if (rowNameC != null) rowName = rowNameC.toString(); if (columnNameC != null) columnName = columnNameC.toString(); } catch (Exception e) { logger.error("error in recovering name of row and column"); return "undef"; } // check if there is a predefined FREETIP message if (enableFreeTip == true) { if (categoriesToolTips.get("FREETIP_X_" + columnName) != null) { String freeName = categoriesToolTips.get("FREETIP_X_" + columnName); return freeName; } } String columnTipName = columnName; String rowTipName = rowName; // check if tip name are defined, else use standard if (categoriesToolTips.get("TIP_X_" + columnName) != null) { columnTipName = categoriesToolTips.get("TIP_X_" + columnName); } // search for series, if seriesCaption has a relative value use it! String serieNameToSearch = null; if (seriesCaption != null) { serieNameToSearch = seriesCaption.get(rowName); } if (serieNameToSearch == null) serieNameToSearch = rowName; if (serieToolTips.get("TIP_" + serieNameToSearch) != null) { rowTipName = serieToolTips.get("TIP_" + serieNameToSearch); } Number num = dataset.getValue(row, column); String numS = (num != null) ? " = " + num.toString() : ""; String toReturn = "(" + columnTipName + ", " + rowTipName + ")" + numS; logger.debug("OUT"); return toReturn; }
From source file:org.jfree.data.general.DatasetUtils.java
/** * Returns the minimum range value for the specified dataset. This is * easy if the dataset implements the {@link RangeInfo} interface (a good * idea if there is an efficient way to determine the minimum value). * Otherwise, it involves iterating over the entire data-set. Returns * {@code null} if all the data values in the dataset are * {@code null}./* ww w. j a v a 2 s . c o m*/ * * @param dataset the dataset ({@code null} not permitted). * * @return The minimum value (possibly {@code null}). */ public static Number findMinimumRangeValue(CategoryDataset dataset) { Args.nullNotPermitted(dataset, "dataset"); if (dataset instanceof RangeInfo) { RangeInfo info = (RangeInfo) dataset; return new Double(info.getRangeLowerBound(true)); } // hasn't implemented RangeInfo, so we'll have to iterate... else { double minimum = Double.POSITIVE_INFINITY; int seriesCount = dataset.getRowCount(); int itemCount = dataset.getColumnCount(); for (int series = 0; series < seriesCount; series++) { for (int item = 0; item < itemCount; item++) { Number value; if (dataset instanceof IntervalCategoryDataset) { IntervalCategoryDataset icd = (IntervalCategoryDataset) dataset; value = icd.getStartValue(series, item); } else { value = dataset.getValue(series, item); } if (value != null) { minimum = Math.min(minimum, value.doubleValue()); } } } if (minimum == Double.POSITIVE_INFINITY) { return null; } else { return new Double(minimum); } } }
From source file:org.jfree.data.general.DatasetUtilities.java
/** * Returns the minimum range value for the specified dataset. This is * easy if the dataset implements the {@link RangeInfo} interface (a good * idea if there is an efficient way to determine the minimum value). * Otherwise, it involves iterating over the entire data-set. Returns * <code>null</code> if all the data values in the dataset are * <code>null</code>.// w w w. j a v a 2 s. co m * * @param dataset the dataset (<code>null</code> not permitted). * * @return The minimum value (possibly <code>null</code>). */ public static Number findMinimumRangeValue(CategoryDataset dataset) { ParamChecks.nullNotPermitted(dataset, "dataset"); if (dataset instanceof RangeInfo) { RangeInfo info = (RangeInfo) dataset; return new Double(info.getRangeLowerBound(true)); } // hasn't implemented RangeInfo, so we'll have to iterate... else { double minimum = Double.POSITIVE_INFINITY; int seriesCount = dataset.getRowCount(); int itemCount = dataset.getColumnCount(); for (int series = 0; series < seriesCount; series++) { for (int item = 0; item < itemCount; item++) { Number value; if (dataset instanceof IntervalCategoryDataset) { IntervalCategoryDataset icd = (IntervalCategoryDataset) dataset; value = icd.getStartValue(series, item); } else { value = dataset.getValue(series, item); } if (value != null) { minimum = Math.min(minimum, value.doubleValue()); } } } if (minimum == Double.POSITIVE_INFINITY) { return null; } else { return new Double(minimum); } } }