Example usage for org.jfree.chart.plot CombinedDomainCategoryPlot setOrientation

List of usage examples for org.jfree.chart.plot CombinedDomainCategoryPlot setOrientation

Introduction

In this page you can find the example usage for org.jfree.chart.plot CombinedDomainCategoryPlot setOrientation.

Prototype

@Override
public void setOrientation(PlotOrientation orientation) 

Source Link

Document

Sets the orientation of the plot (and all subplots).

Usage

From source file:scheduler.benchmarker.manager.CreateCombinedCategoryPlot.java

public ChartPanel createChartPanel() {
    CustomBarRenderer renderer = new CustomBarRenderer(pluginColors);
    CategoryPlot subplot1 = new CategoryPlot(createDataset1(), new CategoryAxis("Category"),
            new NumberAxis("Value"), renderer);
    subplot1.setDomainGridlinesVisible(true);

    CategoryPlot subplot2 = new CategoryPlot(createDataset2(), new CategoryAxis("Category"),
            new NumberAxis("Value"), renderer);
    subplot2.setDomainGridlinesVisible(true);

    final CategoryAxis domainAxis = new CategoryAxis("Category");
    final CombinedDomainCategoryPlot plot = new CombinedDomainCategoryPlot(domainAxis);
    plot.add(subplot1, 1);/*from ww  w  .  ja  v  a  2s.  c o  m*/
    plot.add(subplot2, 1);
    plot.setOrientation(PlotOrientation.HORIZONTAL);
    plot.setFixedLegendItems(createCustomLegend());
    plot.setRenderer(renderer);

    subplot1.setBackgroundPaint(new Color(246, 244, 242));
    subplot2.setBackgroundPaint(new Color(246, 244, 242));

    subplot1.addRangeMarker(generateMarker("CLASSIFICATION FINISH FOR '" + schedNames[0] + "'",
            dataSource[0].getSumTotalTime()), Layer.FOREGROUND);
    subplot2.addRangeMarker(generateMarker("CLASSIFICATION FINISH FOR '" + schedNames[1] + "'",
            dataSource[1].getSumTotalTime()), Layer.FOREGROUND);

    final JFreeChart result = new JFreeChart(title, new Font("SansSerif", Font.BOLD, 12), plot, true);

    cPanel = new ChartPanel(result);
    cPanel.setForeground(new Color(76, 76, 76));
    cPanel.setBackground(new Color(246, 244, 242));

    return cPanel;

}

From source file:it.eng.spagobi.engines.chart.bo.charttypes.barcharts.CombinedCategoryBar.java

public JFreeChart createChart(DatasetMap datasets) {
    logger.debug("IN");

    // recover the datasets
    DefaultCategoryDataset datasetBarFirstAxis = (DefaultCategoryDataset) datasets.getDatasets().get("1-bar");
    DefaultCategoryDataset datasetBarSecondAxis = (DefaultCategoryDataset) datasets.getDatasets().get("2-bar");
    DefaultCategoryDataset datasetLineFirstAxis = (DefaultCategoryDataset) datasets.getDatasets().get("1-line");
    DefaultCategoryDataset datasetLineSecondAxis = (DefaultCategoryDataset) datasets.getDatasets()
            .get("2-line");

    // create the two subplots
    CategoryPlot subPlot1 = new CategoryPlot();
    CategoryPlot subPlot2 = new CategoryPlot();
    CombinedDomainCategoryPlot plot = new CombinedDomainCategoryPlot();

    subPlot1.setDataset(0, datasetBarFirstAxis);
    subPlot2.setDataset(0, datasetBarSecondAxis);

    subPlot1.setDataset(1, datasetLineFirstAxis);
    subPlot2.setDataset(1, datasetLineSecondAxis);

    // localize numbers on y axis
    NumberFormat nf = (NumberFormat) NumberFormat.getNumberInstance(locale);

    // Range Axis 1
    NumberAxis rangeAxis = new NumberAxis(getValueLabel());
    rangeAxis.setLabelFont(new Font(styleXaxesLabels.getFontName(), Font.PLAIN, styleXaxesLabels.getSize()));
    rangeAxis.setLabelPaint(styleXaxesLabels.getColor());
    rangeAxis//from  w  ww  .  j  av  a 2  s .co m
            .setTickLabelFont(new Font(styleXaxesLabels.getFontName(), Font.PLAIN, styleXaxesLabels.getSize()));
    rangeAxis.setTickLabelPaint(styleXaxesLabels.getColor());
    rangeAxis.setUpperMargin(0.10);
    rangeAxis.setNumberFormatOverride(nf);
    subPlot1.setRangeAxis(rangeAxis);
    if (rangeIntegerValues == true) {
        rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    }

    // Range Axis 2
    NumberAxis rangeAxis2 = new NumberAxis(secondAxisLabel);
    rangeAxis2.setLabelFont(new Font(styleXaxesLabels.getFontName(), Font.PLAIN, styleXaxesLabels.getSize()));
    rangeAxis2.setLabelPaint(styleXaxesLabels.getColor());
    rangeAxis2
            .setTickLabelFont(new Font(styleXaxesLabels.getFontName(), Font.PLAIN, styleXaxesLabels.getSize()));
    rangeAxis2.setTickLabelPaint(styleXaxesLabels.getColor());
    rangeAxis2.setUpperMargin(0.10);
    rangeAxis2.setNumberFormatOverride(nf);
    subPlot2.setRangeAxis(rangeAxis2);
    if (rangeIntegerValues == true) {
        rangeAxis2.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    }

    // Category Axis
    CategoryAxis domainAxis = new CategoryAxis(getCategoryLabel());
    domainAxis.setLabelFont(new Font(styleYaxesLabels.getFontName(), Font.PLAIN, styleYaxesLabels.getSize()));
    domainAxis.setLabelPaint(styleYaxesLabels.getColor());
    domainAxis
            .setTickLabelFont(new Font(styleYaxesLabels.getFontName(), Font.PLAIN, styleYaxesLabels.getSize()));
    domainAxis.setTickLabelPaint(styleYaxesLabels.getColor());
    domainAxis.setUpperMargin(0.10);
    plot.setDomainAxis(domainAxis);
    plot.setOrientation(PlotOrientation.VERTICAL);
    plot.setRangeGridlinesVisible(true);
    plot.setDomainGridlinesVisible(true);

    // Add subplots to main plot
    plot.add(subPlot1, 1);
    plot.add(subPlot2, 2);

    MyStandardCategoryItemLabelGenerator generator = null;

    // value labels and additional values are mutually exclusive
    if (showValueLabels == true)
        additionalLabels = false;

    if (additionalLabels) {
        generator = new MyStandardCategoryItemLabelGenerator(catSerLabels, "{1}", NumberFormat.getInstance());
    }

    //      Create Renderers!
    CategoryItemRenderer barRenderer1 = new BarRenderer();
    CategoryItemRenderer barRenderer2 = new BarRenderer();
    LineAndShapeRenderer lineRenderer1 = (useLinesRenderers == true) ? new LineAndShapeRenderer() : null;
    LineAndShapeRenderer lineRenderer2 = (useLinesRenderers == true) ? new LineAndShapeRenderer() : null;

    subPlot1.setRenderer(0, barRenderer1);
    subPlot2.setRenderer(0, barRenderer2);

    if (useLinesRenderers == true) {
        subPlot1.setRenderer(1, lineRenderer1);
        subPlot2.setRenderer(1, lineRenderer2);

        // no shapes for line_no_shapes  series
        for (Iterator iterator = lineNoShapeSeries1.iterator(); iterator.hasNext();) {
            String ser = (String) iterator.next();
            // if there iS a abel associated search for that
            String label = null;
            if (seriesLabelsMap != null) {
                label = (String) seriesLabelsMap.get(ser);
            }
            if (label == null)
                label = ser;
            int index = datasetLineFirstAxis.getRowIndex(label);
            if (index != -1) {
                lineRenderer1.setSeriesShapesVisible(index, false);
            }
        }
        for (Iterator iterator = lineNoShapeSeries2.iterator(); iterator.hasNext();) {
            String ser = (String) iterator.next();
            // if there iS a abel associated search for that

            String label = null;
            if (seriesLabelsMap != null) {
                label = (String) seriesLabelsMap.get(ser);
            }
            if (label == null)
                label = ser;
            int index = datasetLineSecondAxis.getRowIndex(label);
            if (index != -1) {
                lineRenderer2.setSeriesShapesVisible(index, false);
            }
        }

    }

    // add tooltip if enabled
    if (enableToolTips) {
        MyCategoryToolTipGenerator generatorToolTip = new MyCategoryToolTipGenerator(freeToolTips,
                seriesTooltip, categoriesTooltip, seriesCaptions);
        barRenderer1.setToolTipGenerator(generatorToolTip);
        barRenderer2.setToolTipGenerator(generatorToolTip);
        if (useLinesRenderers) {
            lineRenderer1.setToolTipGenerator(generatorToolTip);
            lineRenderer2.setToolTipGenerator(generatorToolTip);
        }
    }

    subPlot1.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
    subPlot2.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

    // COnfigure renderers: I do in extensive way so will be easier to add customization in the future

    if (maxBarWidth != null) {
        ((BarRenderer) barRenderer1).setMaximumBarWidth(maxBarWidth.doubleValue());
        ((BarRenderer) barRenderer2).setMaximumBarWidth(maxBarWidth.doubleValue());
    }

    // Values or addition Labels for first BAR Renderer
    if (showValueLabels) {
        barRenderer1.setBaseItemLabelGenerator(new FilterZeroStandardCategoryItemLabelGenerator());
        barRenderer1.setBaseItemLabelsVisible(true);
        barRenderer1.setBaseItemLabelFont(
                new Font(styleValueLabels.getFontName(), Font.PLAIN, styleValueLabels.getSize()));
        barRenderer1.setBaseItemLabelPaint(styleValueLabels.getColor());

        barRenderer1.setBasePositiveItemLabelPosition(
                new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT));

        barRenderer1.setBaseNegativeItemLabelPosition(
                new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT));

        barRenderer2.setBaseItemLabelGenerator(new FilterZeroStandardCategoryItemLabelGenerator());
        barRenderer2.setBaseItemLabelsVisible(true);
        barRenderer2.setBaseItemLabelFont(
                new Font(styleValueLabels.getFontName(), Font.PLAIN, styleValueLabels.getSize()));
        barRenderer2.setBaseItemLabelPaint(styleValueLabels.getColor());

        barRenderer2.setBasePositiveItemLabelPosition(
                new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT));

        barRenderer2.setBaseNegativeItemLabelPosition(
                new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT));

    } else if (additionalLabels) {
        barRenderer1.setBaseItemLabelGenerator(generator);
        barRenderer2.setBaseItemLabelGenerator(generator);

        double orient = (-Math.PI / 2.0);
        if (styleValueLabels.getOrientation().equalsIgnoreCase("horizontal")) {
            orient = 0.0;
        }

        barRenderer1.setBasePositiveItemLabelPosition(
                new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER, TextAnchor.CENTER, orient));
        barRenderer1.setBaseNegativeItemLabelPosition(
                new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER, TextAnchor.CENTER, orient));
        barRenderer2.setBasePositiveItemLabelPosition(
                new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER, TextAnchor.CENTER, orient));
        barRenderer2.setBaseNegativeItemLabelPosition(
                new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER, TextAnchor.CENTER, orient));

    }

    // Values or addition Labels for line Renderers if requested
    if (useLinesRenderers == true) {
        if (showValueLabels) {
            lineRenderer1.setBaseItemLabelGenerator(new FilterZeroStandardCategoryItemLabelGenerator());
            lineRenderer1.setBaseItemLabelsVisible(true);
            lineRenderer1.setBaseItemLabelFont(
                    new Font(styleValueLabels.getFontName(), Font.PLAIN, styleValueLabels.getSize()));
            lineRenderer1.setBaseItemLabelPaint(styleValueLabels.getColor());
            lineRenderer1.setBasePositiveItemLabelPosition(
                    new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT));
            lineRenderer1.setBaseNegativeItemLabelPosition(
                    new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT));
            lineRenderer2.setBaseItemLabelGenerator(new FilterZeroStandardCategoryItemLabelGenerator());
            lineRenderer2.setBaseItemLabelsVisible(true);
            lineRenderer2.setBaseItemLabelFont(
                    new Font(styleValueLabels.getFontName(), Font.PLAIN, styleValueLabels.getSize()));
            lineRenderer2.setBaseItemLabelPaint(styleValueLabels.getColor());
            lineRenderer2.setBasePositiveItemLabelPosition(
                    new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT));
            lineRenderer2.setBaseNegativeItemLabelPosition(
                    new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT));

        } else if (additionalLabels) {
            lineRenderer1.setBaseItemLabelGenerator(generator);
            lineRenderer2.setBaseItemLabelGenerator(generator);
            double orient = (-Math.PI / 2.0);
            if (styleValueLabels.getOrientation().equalsIgnoreCase("horizontal")) {
                orient = 0.0;
            }
            lineRenderer1.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER,
                    TextAnchor.CENTER, TextAnchor.CENTER, orient));
            lineRenderer1.setBaseNegativeItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER,
                    TextAnchor.CENTER, TextAnchor.CENTER, orient));
            lineRenderer2.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER,
                    TextAnchor.CENTER, TextAnchor.CENTER, orient));
            lineRenderer2.setBaseNegativeItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER,
                    TextAnchor.CENTER, TextAnchor.CENTER, orient));

        }
    }

    // Bar Dataset Colors!
    if (colorMap != null) {
        int idx = -1;
        for (Iterator iterator = datasetBarFirstAxis.getRowKeys().iterator(); iterator.hasNext();) {
            idx++;
            String serName = (String) iterator.next();
            String labelName = "";
            int index = -1;

            if (seriesCaptions != null && seriesCaptions.size() > 0) {
                labelName = serName;
                serName = (String) seriesCaptions.get(serName);
                index = datasetBarFirstAxis.getRowIndex(labelName);
            } else
                index = datasetBarFirstAxis.getRowIndex(serName);

            Color color = (Color) colorMap.get(serName);
            if (color != null) {
                barRenderer1.setSeriesPaint(index, color);
            }
        }

        for (Iterator iterator = datasetBarSecondAxis.getRowKeys().iterator(); iterator.hasNext();) {
            idx++;
            String serName = (String) iterator.next();
            String labelName = "";
            int index = -1;

            if (seriesCaptions != null && seriesCaptions.size() > 0) {
                labelName = serName;
                serName = (String) seriesCaptions.get(serName);
                index = datasetBarSecondAxis.getRowIndex(labelName);
            } else
                index = datasetBarSecondAxis.getRowIndex(serName);

            Color color = (Color) colorMap.get(serName);
            if (color != null) {
                barRenderer2.setSeriesPaint(index, color);
            }
        }
    }

    // LINE Dataset Colors!
    if (useLinesRenderers == true) {
        if (colorMap != null) {
            int idx = -1;
            for (Iterator iterator = datasetLineFirstAxis.getRowKeys().iterator(); iterator.hasNext();) {
                idx++;
                String serName = (String) iterator.next();
                String labelName = "";
                int index = -1;

                if (seriesCaptions != null && seriesCaptions.size() > 0) {
                    labelName = serName;
                    serName = (String) seriesCaptions.get(serName);
                    index = datasetLineFirstAxis.getRowIndex(labelName);
                } else
                    index = datasetLineFirstAxis.getRowIndex(serName);

                Color color = (Color) colorMap.get(serName);
                if (color != null) {
                    lineRenderer1.setSeriesPaint(index, color);
                }
            }

            for (Iterator iterator = datasetLineSecondAxis.getRowKeys().iterator(); iterator.hasNext();) {
                idx++;
                String serName = (String) iterator.next();
                String labelName = "";
                int index = -1;

                if (seriesCaptions != null && seriesCaptions.size() > 0) {
                    labelName = serName;
                    serName = (String) seriesCaptions.get(serName);
                    index = datasetLineSecondAxis.getRowIndex(labelName);
                } else
                    index = datasetLineSecondAxis.getRowIndex(serName);

                Color color = (Color) colorMap.get(serName);
                if (color != null) {
                    lineRenderer2.setSeriesPaint(index, color);
                }
            }
        }
    }

    //defines url for drill
    boolean document_composition = false;
    if (mode.equalsIgnoreCase(SpagoBIConstants.DOCUMENT_COMPOSITION))
        document_composition = true;

    logger.debug("Calling Url Generation");

    MyCategoryUrlGenerator mycatUrl = null;
    if (super.rootUrl != null) {
        logger.debug("Set MycatUrl");
        mycatUrl = new MyCategoryUrlGenerator(super.rootUrl);

        mycatUrl.setDocument_composition(document_composition);
        mycatUrl.setCategoryUrlLabel(super.categoryUrlName);
        mycatUrl.setSerieUrlLabel(super.serieUrlname);
        mycatUrl.setDrillDocTitle(drillDocTitle);
        mycatUrl.setTarget(target);
    }
    if (mycatUrl != null) {
        barRenderer1.setItemURLGenerator(mycatUrl);
        barRenderer2.setItemURLGenerator(mycatUrl);
        if (useLinesRenderers) {
            lineRenderer1.setItemURLGenerator(mycatUrl);
            lineRenderer2.setItemURLGenerator(mycatUrl);
        }

    }

    plot.getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.UP_45);

    JFreeChart chart = new JFreeChart(plot);
    TextTitle title = setStyleTitle(name, styleTitle);
    chart.setTitle(title);
    if (subName != null && !subName.equals("")) {
        TextTitle subTitle = setStyleTitle(subName, styleSubTitle);
        chart.addSubtitle(subTitle);
    }
    chart.setBackgroundPaint(Color.white);

    //      I want to re order the legend
    LegendItemCollection legends = plot.getLegendItems();
    // legend Temp 
    HashMap<String, LegendItem> legendTemp = new HashMap<String, LegendItem>();
    Vector<String> alreadyInserted = new Vector<String>();
    for (int i = 0; i < legends.getItemCount(); i++) {
        LegendItem item = legends.get(i);
        String label = item.getLabel();
        legendTemp.put(label, item);
    }
    LegendItemCollection newLegend = new LegendItemCollection();
    // force the order of the ones specified
    for (Iterator iterator = seriesOrder.iterator(); iterator.hasNext();) {
        String serie = (String) iterator.next();
        if (legendTemp.keySet().contains(serie)) {
            newLegend.add(legendTemp.get(serie));
            alreadyInserted.add(serie);
        }
    }
    // check that there are no serie not specified, otherwise add them
    for (Iterator iterator = legendTemp.keySet().iterator(); iterator.hasNext();) {
        String serie = (String) iterator.next();
        if (!alreadyInserted.contains(serie)) {
            newLegend.add(legendTemp.get(serie));
        }
    }

    plot.setFixedLegendItems(newLegend);

    if (legend == true)
        drawLegend(chart);
    logger.debug("OUT");

    return chart;

}