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

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

Introduction

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

Prototype

public List getColumnKeys();

Source Link

Document

Returns the column keys.

Usage

From source file:org.talend.dataprofiler.chart.ChartDecorator.java

/**
 * DOC bZhou Comment method "decorateCategoryPlot".
 * /*from  ww w  .j  a  va  2 s  .  co m*/
 * @param chart
 */
public static void decorateCategoryPlot(JFreeChart chart, PlotOrientation orientation) {

    CategoryPlot plot = chart.getCategoryPlot();
    CategoryItemRenderer render = plot.getRenderer();
    CategoryAxis domainAxis = plot.getDomainAxis();
    // ADD msjian TDQ-5111 2012-4-9: set something look it well
    domainAxis.setCategoryMargin(0.1);
    domainAxis.setUpperMargin(0.05);
    domainAxis.setLowerMargin(0.05);
    domainAxis.setCategoryLabelPositionOffset(10);
    // TDQ-5111~

    ValueAxis valueAxis = plot.getRangeAxis();

    Font font = new Font("Tahoma", Font.BOLD, BASE_ITEM_LABEL_SIZE);//$NON-NLS-1$

    render.setBaseItemLabelFont(font);
    // MOD zshen 10998: change the font name 2010-01-16
    font = new Font("sans-serif", Font.BOLD, BASE_LABEL_SIZE);//$NON-NLS-1$
    domainAxis.setLabelFont(font);

    font = new Font("sans-serif", Font.BOLD, BASE_LABEL_SIZE);//$NON-NLS-1$
    valueAxis.setLabelFont(font);

    font = new Font("sans-serif", Font.PLAIN, BASE_TICK_LABEL_SIZE);//$NON-NLS-1$
    domainAxis.setTickLabelFont(font);
    valueAxis.setTickLabelFont(font);

    setLegendFont(chart);

    font = new Font("sans-serif", Font.BOLD, BASE_TITLE_LABEL_SIZE);//$NON-NLS-1$
    TextTitle title = chart.getTitle();
    if (title != null) {
        title.setFont(font);
    }

    font = null;

    if (render instanceof BarRenderer) {
        CategoryDataset dataset = chart.getCategoryPlot().getDataset();
        if (dataset != null) {
            int rowCount = dataset.getRowCount();
            List<?> columnKeys = dataset.getColumnKeys();
            if (!isContainCJKCharacter(columnKeys.toArray())) {
                domainAxis.setTickLabelFont(new Font("Tahoma", Font.PLAIN, 10));//$NON-NLS-1$
            }
            ((BarRenderer) render).setItemMargin(-0.40 * rowCount);

            // TDQ-12621 add Tooltip for Lable
            for (Object colKey : columnKeys) {
                domainAxis.addCategoryLabelToolTip(colKey.toString(), colKey.toString());
            }
        }
        domainAxis.setUpperMargin(0.1);
        // TDQ-12621 Only display in 1 line for the label, other chars will be displayed as "..."
        domainAxis.setMaximumCategoryLabelLines(1);

        // ADD msjian TDQ-5111 2012-4-9: set Bar Width and let it look well
        // not do this when the bar is horizontal Orientation
        if (orientation == null) {
            ((BarRenderer) render).setMaximumBarWidth(0.2);
        }
        // TDQ-5111~
    }
    // ~10998
}

From source file:net.sf.maltcms.common.charts.api.overlay.AbstractChartOverlay.java

/**
 *
 * @param chartPanel/*from w  ww . ja v  a  2  s.c om*/
 * @param category
 * @param y
 * @return
 */
public static AffineTransform getModelToViewTransformCategory(ChartPanel chartPanel, int category, double y) {
    double zoomX = chartPanel.getScaleX();
    double zoomY = chartPanel.getScaleY();
    Insets insets = chartPanel.getInsets();
    AffineTransform at = getTranslateInstance(insets.left, insets.top);
    at.concatenate(getScaleInstance(zoomX, zoomY));
    Plot plot = chartPanel.getChart().getPlot();
    if (plot instanceof CategoryPlot) {
        CategoryPlot xyp = (CategoryPlot) plot;
        CategoryDataset cds = xyp.getDataset();
        RectangleEdge xAxisLocation = xyp.getDomainAxisEdge();
        RectangleEdge yAxisLocation = xyp.getRangeAxisEdge();
        PlotOrientation orientation = xyp.getOrientation();
        Comparable<?> categoryKey = cds.getColumnKey(category);
        Rectangle2D dataArea = chartPanel.getChartRenderingInfo().getPlotInfo().getDataArea();
        double transX = xyp.getDomainAxis().getCategoryMiddle(categoryKey, cds.getColumnKeys(), dataArea,
                xAxisLocation);
        double transY = xyp.getRangeAxis().valueToJava2D(y, dataArea, yAxisLocation);
        if (orientation == PlotOrientation.HORIZONTAL) {
            double tmp = transX;
            transX = transY;
            transY = tmp;
        }
        at.concatenate(getTranslateInstance(transX, transY));
        return at;
    }
    throw new IllegalArgumentException("Unsupported plot type: " + plot.getClass());
}

From source file:org.pau.assetmanager.viewmodel.chart.PrepareChart.java

public static void prepareJFreeBarChart(JFreeChart jfchart, List<PropertyBook> listOfPropertties,
        CategoryDataset categoryModel) {

    CategoryPlot categoryPlot = ((CategoryPlot) jfchart.getPlot());
    categoryPlot.getRangeAxis().resizeRange(1.2);
    categoryPlot.setBackgroundPaint(Color.WHITE);
    categoryPlot.setDomainGridlinePaint(Color.WHITE);
    categoryPlot.setRangeMinorGridlinePaint(Color.WHITE);
    categoryPlot.setRangeGridlinePaint(Color.BLACK);
    BarRenderer renderer = (BarRenderer) categoryPlot.getRenderer();

    renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    renderer.setBaseItemLabelsVisible(false);
    for (int i = 0; i < listOfPropertties.size(); i++) {
        renderer.setSeriesStroke(i, new BasicStroke(1));
    }/*w  ww  .  j a v  a2 s .  c om*/
    for (int i = 0; i < categoryModel.getColumnKeys().size(); i++) {
        String label = (String) categoryModel.getColumnKey(i);
        CategoryMarker marker = new CategoryMarker(label);
        marker.setLabel("");
        marker.setPaint(Color.cyan);
        marker.setOutlinePaint(Color.cyan);
        marker.setAlpha(0.1f);
        marker.setLabelAnchor(RectangleAnchor.TOP);
        marker.setLabelTextAnchor(TextAnchor.TOP_CENTER);
        marker.setLabelOffsetType(LengthAdjustmentType.CONTRACT);
        categoryPlot.addDomainMarker(marker, Layer.BACKGROUND);
    }
    renderer.setDrawBarOutline(false);
    renderer.setShadowVisible(false);
    renderer.setItemMargin(.1);
    renderer.setBarPainter(new StandardBarPainter());

}

From source file:org.talend.dataprofiler.chart.preview.CustomRenderer.java

@Override
public Paint getItemPaint(int i, int j) {
    CategoryDataset categorydataset = getPlot().getDataset();
    int m = Integer.parseInt(categorydataset.getColumnKeys().get(j).toString());
    return colors[m % colors.length];
}

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./*  w w w .  j  a  v  a  2 s .com*/
 * @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.//from w  w w.ja  va2s  .  c  o m
 * @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.pentaho.plugin.jfreereport.reportcharts.MultiPieChartExpression.java

protected void configureChart(final JFreeChart chart) {
    super.configureChart(chart);

    final Plot plot = chart.getPlot();
    final MultiplePiePlot mpp = (MultiplePiePlot) plot;
    final JFreeChart pc = mpp.getPieChart();
    configureSubChart(pc);//from  w  ww .  j a v a2  s.com

    final PiePlot pp = (PiePlot) pc.getPlot();
    if (StringUtils.isEmpty(getTooltipFormula()) == false) {
        pp.setToolTipGenerator(new FormulaPieTooltipGenerator(getRuntime(), getTooltipFormula()));
    }
    if (StringUtils.isEmpty(getUrlFormula()) == false) {
        pp.setURLGenerator(new FormulaPieURLGenerator(getRuntime(), getUrlFormula()));
    }

    if (shadowPaint != null) {
        pp.setShadowPaint(shadowPaint);
    }
    if (shadowXOffset != null) {
        pp.setShadowXOffset(shadowXOffset.doubleValue());
    }
    if (shadowYOffset != null) {
        pp.setShadowYOffset(shadowYOffset.doubleValue());
    }

    final CategoryDataset c = mpp.getDataset();
    if (c != null) {
        final String[] colors = getSeriesColor();
        final int keysSize = c.getColumnKeys().size();
        for (int i = 0; i < colors.length; i++) {
            if (keysSize > i) {
                pp.setSectionPaint(c.getColumnKey(i), parseColorFromString(colors[i]));
            }
        }
    }

    if (StringUtils.isEmpty(getLabelFont()) == false) {
        pp.setLabelFont(Font.decode(getLabelFont()));
    }

    if (Boolean.FALSE.equals(getItemsLabelVisible())) {
        pp.setLabelGenerator(null);
    } else {
        final ExpressionRuntime runtime = getRuntime();
        final Locale locale = runtime.getResourceBundleFactory().getLocale();

        final FastDecimalFormat fastPercent = new FastDecimalFormat(FastDecimalFormat.TYPE_PERCENT, locale);
        final FastDecimalFormat fastInteger = new FastDecimalFormat(FastDecimalFormat.TYPE_INTEGER, locale);

        final DecimalFormat numFormat = new DecimalFormat(fastInteger.getPattern(),
                new DecimalFormatSymbols(locale));
        numFormat.setRoundingMode(RoundingMode.HALF_UP);

        final DecimalFormat percentFormat = new DecimalFormat(fastPercent.getPattern(),
                new DecimalFormatSymbols(locale));
        percentFormat.setRoundingMode(RoundingMode.HALF_UP);

        final StandardPieSectionLabelGenerator labelGen = new StandardPieSectionLabelGenerator(
                multipieLabelFormat, numFormat, percentFormat);
        pp.setLabelGenerator(labelGen);
    }
}

From source file:org.talend.dataprofiler.chart.util.TopChartFactory.java

/**
 * /*from  ww w  .j av  a  2 s .c  o m*/
 * DOC zshen Comment method "createMatchRuleBarChart".
 * 
 * @param title
 * @param dataset
 * @return
 */
public static JFreeChart createMatchRuleBarChart(String categoryAxisLabel, String valueAxisLabel,
        CategoryDataset dataset) {
    ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme());
    JFreeChart localJFreeChart = ChartFactory.createBarChart(null, categoryAxisLabel, valueAxisLabel, dataset,
            PlotOrientation.VERTICAL, false, true, false);

    localJFreeChart.addSubtitle(new TextTitle(
            Messages.getString("DataChart.title", sumItemCount(dataset), sumGroupCount(dataset)))); //$NON-NLS-1$
    CategoryPlot plot = (CategoryPlot) localJFreeChart.getPlot();
    // get real color list from ChartDecorator.COLOR_LIST dataset.getColumnKeys()
    List<Color> currentColorList = null;
    try {
        currentColorList = getCurrentColorList(dataset.getColumnKeys());
    } catch (NumberFormatException e) {
        log.warn(e, e);
        currentColorList = ChartDecorator.COLOR_LIST;
    }
    BarRenderer barRenderer = new TalendBarRenderer(true, currentColorList);
    barRenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    barRenderer.setBaseItemLabelsVisible(true);
    // remove the shadow
    barRenderer.setShadowVisible(Boolean.FALSE);
    plot.setRenderer(barRenderer);

    CategoryAxis localCategoryAxis = plot.getDomainAxis();
    localCategoryAxis.setCategoryMargin(0.25D);
    localCategoryAxis.setUpperMargin(0.02D);
    localCategoryAxis.setLowerMargin(0.02D);

    NumberAxis localNumberAxis = (NumberAxis) plot.getRangeAxis();
    localNumberAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    localNumberAxis.setUpperMargin(0.1D);
    return localJFreeChart;
}

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 ww  w .  ja  va2 s .  c  o m
 */
@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:org.pau.assetmanager.viewmodel.chart.PrepareChart.java

public static void preparePropertiesVsOwnAllPropertiesJFreeChart(JFreeChart jfchart,
        CategoryDataset categoryModel) {

    CategoryPlot categoryPlot = ((CategoryPlot) jfchart.getPlot());
    categoryPlot.getRangeAxis().resizeRange(1.2);
    categoryPlot.setBackgroundPaint(Color.WHITE);
    categoryPlot.setDomainGridlinePaint(Color.WHITE);
    categoryPlot.setRangeMinorGridlinePaint(Color.WHITE);
    categoryPlot.setRangeGridlinePaint(Color.BLACK);
    BarRenderer renderer = (BarRenderer) categoryPlot.getRenderer();

    renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    renderer.setBaseItemLabelsVisible(true);

    renderer.setBaseItemLabelFont(new Font("Serif", Font.PLAIN, 10));
    renderer.setItemLabelAnchorOffset(15);

    renderer.setSeriesStroke(0, new BasicStroke(1));
    renderer.setSeriesStroke(1, new BasicStroke(1));
    renderer.setSeriesStroke(2, new BasicStroke(1));
    renderer.setSeriesStroke(3, new BasicStroke(1));
    renderer.setSeriesStroke(4, new BasicStroke(1));
    renderer.setSeriesStroke(5, new BasicStroke(1));
    renderer.setSeriesPaint(0, new Color(0x77, 0x77, 0xFF));
    renderer.setSeriesPaint(1, new Color(0xCC, 0xCC, 0xFF));
    renderer.setSeriesPaint(2, new Color(0x00, 0x00, 0xFF));
    renderer.setSeriesPaint(3, new Color(0xFF, 0x77, 0x77));
    renderer.setSeriesPaint(4, new Color(0xFF, 0xCC, 0xCC));
    renderer.setSeriesPaint(5, new Color(0xFF, 0x00, 0x00));
    for (int i = 0; i < categoryModel.getColumnKeys().size(); i++) {
        String label = (String) categoryModel.getColumnKey(i);
        CategoryMarker marker = new CategoryMarker(label);
        marker.setLabel("");
        marker.setPaint(Color.cyan);
        marker.setOutlinePaint(Color.cyan);
        marker.setAlpha(0.1f);// w w  w.  ja va 2 s.c  o  m
        marker.setLabelAnchor(RectangleAnchor.TOP);
        marker.setLabelTextAnchor(TextAnchor.TOP_CENTER);
        marker.setLabelOffsetType(LengthAdjustmentType.CONTRACT);
        categoryPlot.addDomainMarker(marker, Layer.BACKGROUND);
    }
    renderer.setDrawBarOutline(false);
    renderer.setShadowVisible(false);
    renderer.setItemMargin(.1);
    renderer.setBarPainter(new StandardBarPainter());
    renderer.setBasePositiveItemLabelPosition(
            new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.TOP_RIGHT));
    renderer.setBaseNegativeItemLabelPosition(
            new ItemLabelPosition(ItemLabelAnchor.OUTSIDE6, TextAnchor.BOTTOM_RIGHT));
}