Example usage for org.jfree.data.category CategoryDataset getRowKeys

List of usage examples for org.jfree.data.category CategoryDataset getRowKeys

Introduction

In this page you can find the example usage for org.jfree.data.category CategoryDataset getRowKeys.

Prototype

public List getRowKeys();

Source Link

Document

Returns the row keys.

Usage

From source file:edu.ucla.stat.SOCR.chart.gui.SOCRSpiderWebPlot.java

/**         * Returns a collection of legend items for the radar chart.
 *          * @return The legend items.//from w w  w. j  a v  a  2  s. c o m
 */
public LegendItemCollection getLegendItems() {
    LegendItemCollection result = new LegendItemCollection();

    CategoryDataset dataset = super.getDataset();

    s = new Summary(dataset);
    List keys = null;

    keys = dataset.getRowKeys();

    if (keys != null) {
        int series = 0;
        Iterator iterator = keys.iterator();
        Shape shape = getLegendItemShape();

        while (iterator.hasNext()) {
            String label = iterator.next().toString() + ":" + s.getSeriesSummary(series) + "\n";
            ;
            String description = label;

            Paint paint = getSeriesPaint(series);
            Paint outlinePaint = getSeriesOutlinePaint(series);
            Stroke stroke = getSeriesOutlineStroke(series);
            LegendItem item = new LegendItem(label, description, null, null, shape, paint, stroke,
                    outlinePaint);
            result.add(item);
            series++;
        }
    }

    return result;
}

From source file:org.pentaho.plugin.jfreereport.reportcharts.FormulaCategoryTooltipGenerator.java

/**
 * Generates the tool tip text for an item in a dataset.  Note: in the current dataset implementation, each row is a
 * series, and each column contains values for a particular category.
 *
 * @param dataset  the dataset (<code>null</code> not permitted).
 * @param series   the series (zero-based index).
 * @param category the category.//from   w  w w .j a va  2s  . co  m
 * @return The tooltip text (possibly <code>null</code>).
 */
public String generateToolTip(final CategoryDataset dataset, final int series, final int category) {
    try {
        final Comparable seriesKey = dataset.getRowKey(series);
        final Comparable categoryKey = dataset.getColumnKey(category);
        final Object[] categoryKeys = dataset.getColumnKeys().toArray();
        final Object[] seriesKeys = dataset.getRowKeys().toArray();
        final Object value = dataset.getValue(series, category);

        final Object[] values = new Object[] { seriesKey, categoryKey, IntegerCache.getInteger(series),
                IntegerCache.getInteger(category), seriesKeys, categoryKeys, value };
        final StaticDataRow datarow = new StaticDataRow(ADDITIONAL_COLUMN_KEYS, values);
        final WrapperExpressionRuntime wrapper = new WrapperExpressionRuntime(datarow, runtime);
        formulaExpression.setRuntime(wrapper);
        final Object o = formulaExpression.getValue();
        if (o == null) {
            return null;
        }
        return String.valueOf(o);
    } finally {
        formulaExpression.setRuntime(null);
    }
}

From source file:org.pentaho.plugin.jfreereport.reportcharts.FormulaCategoryURLGenerator.java

/**
 * Returns a URL for one item in a dataset. As a guideline, the URL should be valid within the context of an XHTML 1.0
 * document.  Classes that implement this interface are responsible for correctly escaping any text that is derived
 * from the dataset, as this may be user-specified and could pose a security risk.
 *
 * @param dataset  the dataset./*ww  w . j av  a 2s. com*/
 * @param series   the series (zero-based index).
 * @param category the category.
 * @return A string containing the URL.
 */
public String generateURL(final CategoryDataset dataset, final int series, final int category) {
    try {
        final Comparable seriesKey = dataset.getRowKey(series);
        final Comparable categoryKey = dataset.getColumnKey(category);
        final Object[] categoryKeys = dataset.getColumnKeys().toArray();
        final Object[] seriesKeys = dataset.getRowKeys().toArray();
        final Object value = dataset.getValue(series, category);

        final Object[] values = new Object[] { seriesKey, categoryKey, IntegerCache.getInteger(series),
                IntegerCache.getInteger(category), seriesKeys, categoryKeys, value };
        final StaticDataRow datarow = new StaticDataRow(ADDITIONAL_COLUMN_KEYS, values);
        final WrapperExpressionRuntime wrapper = new WrapperExpressionRuntime(datarow, runtime);
        formulaExpression.setRuntime(wrapper);
        final Object o = formulaExpression.getValue();
        if (o == null) {
            return null;
        }
        return String.valueOf(o);
    } finally {
        formulaExpression.setRuntime(null);
    }
}

From source file:org.jfree.data.category.DefaultCategoryDataset.java

/**
 * Tests this dataset for equality with an arbitrary object.
 *
 * @param obj  the object (<code>null</code> permitted).
 *
 * @return A boolean./*from w ww. ja  va  2 s . c  om*/
 */
@Override
public boolean equals(Object obj) {
    if (obj == this) {
        return true;
    }
    if (!(obj instanceof CategoryDataset)) {
        return false;
    }
    CategoryDataset that = (CategoryDataset) obj;
    if (!getRowKeys().equals(that.getRowKeys())) {
        return false;
    }
    if (!getColumnKeys().equals(that.getColumnKeys())) {
        return false;
    }
    int rowCount = getRowCount();
    int colCount = getColumnCount();
    for (int r = 0; r < rowCount; r++) {
        for (int c = 0; c < colCount; c++) {
            Number v1 = getValue(r, c);
            Number v2 = that.getValue(r, c);
            if (v1 == null) {
                if (v2 != null) {
                    return false;
                }
            } else if (!v1.equals(v2)) {
                return false;
            }
        }
    }
    return true;
}

From source file:uk.ac.lkl.cram.ui.chart.LearningExperienceChartMaker.java

/**
 * Create a chart from the provide category dataset
 * @return a Chart that can be rendered in a ChartPanel
 *//* w ww  . j av a2s . co m*/
@Override
protected JFreeChart createChart() {
    //Create a horizontal stacked bar chart from the chart factory, with no title, no axis labels, a legend, tooltips but no URLs
    JFreeChart chart = ChartFactory.createStackedBarChart(null, null, null, (CategoryDataset) dataset,
            PlotOrientation.HORIZONTAL, true, true, false);
    //Get the plot from the chart
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    //Remove offsets from the plot
    plot.setInsets(RectangleInsets.ZERO_INSETS);
    plot.setAxisOffset(RectangleInsets.ZERO_INSETS);
    //Hide the range lines
    plot.setRangeGridlinesVisible(false);
    //Get the renderer for the plot
    StackedBarRenderer sbRenderer = (StackedBarRenderer) plot.getRenderer();
    //Set the painter for the renderer (nothing fancy)
    sbRenderer.setBarPainter(new StandardBarPainter());
    //sbRenderer.setItemMargin(0.5); //Makes no difference
    //reduces width of bar as proportion of overall width
    sbRenderer.setMaximumBarWidth(0.5);
    //Render the bars as percentages
    sbRenderer.setRenderAsPercentages(true);
    //Set the colours for the bars
    sbRenderer.setSeriesPaint(0, PERSONALISED_COLOR);
    sbRenderer.setSeriesPaint(1, SOCIAL_COLOR);
    sbRenderer.setSeriesPaint(2, ONE_SIZE_FOR_ALL_COLOR);
    //Set the tooltips to render percentages
    sbRenderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator() {

        @Override
        public String generateToolTip(CategoryDataset cd, int row, int column) {
            //Only interested in row, as there's only one column
            //TODO--really inefficient
            @SuppressWarnings("unchecked")
            List<Comparable> rows = cd.getRowKeys();
            Comparable columnKey = cd.getColumnKey(column);
            //Sum running total
            int total = 0;
            for (Comparable comparable : rows) {
                total += cd.getValue(comparable, columnKey).intValue();
            }
            //Get the value for the row (in our case the learning type)
            Comparable rowKey = cd.getRowKey(row);
            float value = cd.getValue(rowKey, columnKey).floatValue();
            //The tooltip is the value of the learning type divided by the total, expressed as a percentage
            @SuppressWarnings("StringBufferWithoutInitialCapacity")
            StringBuilder builder = new StringBuilder();
            builder.append("<html><center>");
            builder.append(cd.getRowKey(row));
            builder.append(" (");
            builder.append(FORMATTER.format(value / total));
            builder.append(")<br/>");
            builder.append("Double-click for more");
            return builder.toString();
        }
    });
    //Hide both axes
    CategoryAxis categoryAxis = plot.getDomainAxis();
    //categoryAxis.setCategoryMargin(0.5D);//Makes no difference
    categoryAxis.setVisible(false);
    NumberAxis numberAxis = (NumberAxis) plot.getRangeAxis();
    numberAxis.setVisible(false);
    return chart;
}

From source file:org.pentaho.chart.plugin.jfreechart.utils.JFreeChartUtils.java

/**
 * @param chartDocument//from   w  w w  .j  a  v a  2  s  .  c  o m
 * @param data
 * @return
 */
public static KeyToGroupMap createKeyToGroupMap(final ChartDocument chartDocument, final ChartTableModel data,
        final CategoryDataset dataSet) {
    ChartElement groupElement = getBaseStackedGroupElement(chartDocument);

    // First build the set of keys to match against
    final Set matchSet = new HashSet();
    final int rowCount = data.getRowCount();
    for (int row = 0; row < rowCount; row++) {
        final StringBuffer keyStr = new StringBuffer();
        final int groupDepth = getGroupDepth(groupElement);
        for (int i = 0; i < groupDepth; i++) {
            final String columnName = groupElement.getAttribute(ChartElement.COLUMN_NAME).toString();
            final int columnNum = data.findColumn(columnName);
            keyStr.append(data.getValueAt(row, columnNum)).append(SEPERATOR);
            groupElement = getChildGroup(groupElement);
        }
        matchSet.add(keyStr.toString());
        groupElement = getBaseStackedGroupElement(chartDocument);
    }

    // Now we match them and add then to an appropriate group
    final KeyToGroupMap keyToGroupMap = new KeyToGroupMap();

    for (final Object aMatchSet : matchSet) {
        final String matchStr = aMatchSet.toString();
        final Iterator rowHeaderIterator = dataSet.getRowKeys().iterator();
        while (rowHeaderIterator.hasNext()) {
            final String rowHeader = aMatchSet.toString();
            if (rowHeader.startsWith(matchStr)) {
                keyToGroupMap.mapKeyToGroup(rowHeader, matchStr);
            }
        }
    }

    return keyToGroupMap;
}