Example usage for org.jfree.data KeyToGroupMap KeyToGroupMap

List of usage examples for org.jfree.data KeyToGroupMap KeyToGroupMap

Introduction

In this page you can find the example usage for org.jfree.data KeyToGroupMap KeyToGroupMap.

Prototype

public KeyToGroupMap() 

Source Link

Document

Creates a new map with a default group named 'Default Group'.

Usage

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

/**
 * @param chartDocument/*from w  w  w.j av  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;
}