Example usage for org.jfree.chart ChartFactory createStackedBarChart

List of usage examples for org.jfree.chart ChartFactory createStackedBarChart

Introduction

In this page you can find the example usage for org.jfree.chart ChartFactory createStackedBarChart.

Prototype

public static JFreeChart createStackedBarChart(String title, String domainAxisLabel, String rangeAxisLabel,
        CategoryDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls) 

Source Link

Document

Creates a stacked bar chart with default settings.

Usage

From source file:RDGraphGenerator.java

private JFreeChart createTimeChart(String riderID) {

    String riderName = (String) riders.get(riderID);
    final JFreeChart chart = ChartFactory.createStackedBarChart(riderName + "'s Hours", // chart title
            "Month", // domain axis label
            "Hours", // range axis label
            (CategoryDataset) riderTimes.get(riderID), // data
            PlotOrientation.VERTICAL, // the plot orientation
            true, // legend
            true, // tooltips
            false // urls
    );//from   w  w  w. ja  va  2s. c  om

    GroupedStackedBarRenderer renderer = new GroupedStackedBarRenderer();
    KeyToGroupMap map = new KeyToGroupMap("G1");
    map.mapKeyToGroup("0", "G1");
    map.mapKeyToGroup("1", "G1");
    map.mapKeyToGroup("2", "G1");
    map.mapKeyToGroup("3", "G1");
    renderer.setSeriesToGroupMap(map);

    renderer.setItemMargin(0.0);
    Paint p1 = new GradientPaint(0.0f, 0.0f, new Color(0x22, 0x22, 0xFF), 0.0f, 0.0f,
            new Color(0x88, 0x88, 0xFF));
    renderer.setSeriesPaint(0, p1);

    Paint p2 = new GradientPaint(0.0f, 0.0f, new Color(0x22, 0xFF, 0x22), 0.0f, 0.0f,
            new Color(0x88, 0xFF, 0x88));
    renderer.setSeriesPaint(1, p2);

    Paint p3 = new GradientPaint(0.0f, 0.0f, new Color(0xFF, 0x22, 0x22), 0.0f, 0.0f,
            new Color(0xFF, 0x88, 0x88));
    renderer.setSeriesPaint(2, p3);

    Paint p4 = new GradientPaint(0.0f, 0.0f, new Color(0xFF, 0xFF, 0x22), 0.0f, 0.0f,
            new Color(0xFF, 0xFF, 0x88));
    renderer.setSeriesPaint(3, p4);
    renderer.setGradientPaintTransformer(
            new StandardGradientPaintTransformer(GradientPaintTransformType.HORIZONTAL));

    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setRenderer(renderer);
    plot.setFixedLegendItems(createLegendItems());
    CategoryAxis ca = plot.getDomainAxis();
    ca.setCategoryLabelPositions(CategoryLabelPositions.DOWN_90);
    //Make around the chart transparent.
    chart.setBackgroundPaint(null);
    return chart;

}

From source file:org.jfree.chart.demo.JFreeChartDemoBase.java

/**
 * Creates and returns a sample stacked horizontal bar chart.
 *
 * @return a sample stacked horizontal bar chart.
 *//* w w  w .jav  a  2s  .  c  o m*/
public JFreeChart createStackedHorizontalBarChart() {

    // create a default chart based on some sample data...
    final String title = this.resources.getString("bar.horizontal-stacked.title");
    final String domain = this.resources.getString("bar.horizontal-stacked.domain");
    final String range = this.resources.getString("bar.horizontal-stacked.range");

    final CategoryDataset data = DemoDatasetFactory.createCategoryDataset();
    final JFreeChart chart = ChartFactory.createStackedBarChart(title, domain, range, data,
            PlotOrientation.HORIZONTAL, true, true, false);

    // then customise it a little...
    chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 1000, 0, Color.blue));
    return chart;

}

From source file:com.voterData.graph.Graph.java

public static JFreeChart getEthnicityDistbn(Map<String, Double> dataMap) {
    DefaultCategoryDataset defaultcategorydataset = new DefaultCategoryDataset();
    for (String key : dataMap.keySet()) {
        if (key.equals("HL_Dem_2008")) {
            defaultcategorydataset.addValue(dataMap.get(key), "DEM", "HL_2008");
        } else if (key.equals("HL_Rep_2008")) {
            defaultcategorydataset.addValue(dataMap.get(key), "REP", "HL_2008");
        } else if (key.equals("HL_Una_2008")) {
            defaultcategorydataset.addValue(dataMap.get(key), "UNA", "HL_2008");
        } else if (key.equals("NL_Dem_2008")) {
            defaultcategorydataset.addValue(dataMap.get(key), "DEM", "NL_2008");
        } else if (key.equals("NL_Rep_2008")) {
            defaultcategorydataset.addValue(dataMap.get(key), "REP", "NL_2008");
        } else if (key.equals("NL_Una_2008")) {
            defaultcategorydataset.addValue(dataMap.get(key), "UNA", "NL_2008");
        } else if (key.equals("UN_Dem_2008")) {
            defaultcategorydataset.addValue(dataMap.get(key), "DEM", "UN_2008");
        } else if (key.equals("UN_Rep_2008")) {
            defaultcategorydataset.addValue(dataMap.get(key), "REP", "UN_2008");
        } else if (key.equals("UN_Una_2008")) {
            defaultcategorydataset.addValue(dataMap.get(key), "UNA", "UN_2008");
        } else if (key.equals("HL_Dem_2012")) {
            defaultcategorydataset.addValue(dataMap.get(key), "DEM", "HL_2012");
        } else if (key.equals("HL_Rep_2012")) {
            defaultcategorydataset.addValue(dataMap.get(key), "REP", "HL_2012");
        } else if (key.equals("HL_Una_2012")) {
            defaultcategorydataset.addValue(dataMap.get(key), "UNA", "HL_2012");
        } else if (key.equals("NL_Dem_2012")) {
            defaultcategorydataset.addValue(dataMap.get(key), "DEM", "NL_2012");
        } else if (key.equals("NL_Rep_2012")) {
            defaultcategorydataset.addValue(dataMap.get(key), "REP", "NL_2012");
        } else if (key.equals("NL_Una_2012")) {
            defaultcategorydataset.addValue(dataMap.get(key), "UNA", "NL_2012");
        } else if (key.equals("UN_Dem_2012")) {
            defaultcategorydataset.addValue(dataMap.get(key), "DEM", "UN_2012");
        } else if (key.equals("UN_Rep_2012")) {
            defaultcategorydataset.addValue(dataMap.get(key), "REP", "UN_2012");
        } else if (key.equals("UN_Una_2012")) {
            defaultcategorydataset.addValue(dataMap.get(key), "UNA", "UN_2012");
        }/*w  w  w . j  av a2 s.c om*/

    }

    JFreeChart jfreechart = ChartFactory.createStackedBarChart("Ethnicity based Distribution", "Ethnicity_Year",
            "Total Count", defaultcategorydataset, PlotOrientation.HORIZONTAL, true, true, false);
    jfreechart.setBackgroundPaint(Color.white);
    CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
    categoryplot.setBackgroundPaint(Color.lightGray);
    categoryplot.setRangeGridlinePaint(Color.white);
    StackedBarRenderer renderer = (StackedBarRenderer) categoryplot.getRenderer();

    renderer.setDrawBarOutline(false);
    renderer.setSeriesPaint(0, Color.green);
    renderer.setSeriesPaint(1, Color.blue);
    renderer.setSeriesPaint(2, Color.red);
    renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    renderer.setSeriesItemLabelGenerator(0, new StandardCategoryItemLabelGenerator());
    renderer.setItemLabelsVisible(true);
    categoryplot.setRenderer(renderer);

    return jfreechart;

}

From source file:org.jfree.chart.demo.JFreeChartDemoBase.java

/**
 * Creates and returns a sample stacked vertical bar chart.
 *
 * @return a sample stacked vertical bar chart.
 *///from w w w. j a va2 s. c om
public JFreeChart createVerticalStackedBarChart() {

    // create a default chart based on some sample data...
    final String title = this.resources.getString("bar.vertical-stacked.title");
    final String domain = this.resources.getString("bar.vertical-stacked.domain");
    final String range = this.resources.getString("bar.vertical-stacked.range");

    final CategoryDataset data = DemoDatasetFactory.createCategoryDataset();
    final JFreeChart chart = ChartFactory.createStackedBarChart(title, domain, range, data,
            PlotOrientation.VERTICAL, true, true, false);

    // then customise it a little...
    chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 1000, 0, Color.red));
    return chart;

}

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

/**
 * Inherited by IChart./*from  w w  w .j  a v a 2  s. c o  m*/
 * 
 * @param chartTitle the chart title
 * @param dataset the dataset
 * 
 * @return the j free chart
 */

public JFreeChart createChart(DatasetMap datasets) {

    logger.debug("IN");
    CategoryDataset dataset = (CategoryDataset) datasets.getDatasets().get("1");

    logger.debug("Get plot orientaton");
    PlotOrientation plotOrientation = PlotOrientation.VERTICAL;
    if (horizontalView) {
        plotOrientation = PlotOrientation.HORIZONTAL;
    }

    JFreeChart chart = ChartFactory.createStackedBarChart(name, // chart title
            categoryLabel, // domain axis label
            valueLabel, // range axis label
            dataset, // data
            plotOrientation, // the plot orientation
            legend, // legend
            true, // tooltips
            false // urls
    );

    chart.setBackgroundPaint(Color.white);
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setBackgroundPaint(color);
    plot.setRangeGridlinePaint(Color.white);
    plot.setDomainGridlinePaint(Color.white);
    plot.setDomainGridlinesVisible(true);

    GroupedStackedBarRenderer renderer = new GroupedStackedBarRenderer();
    KeyToGroupMap map = new KeyToGroupMap("G1");
    int numElForGroup = 0;
    for (int idx = 0; idx < numGroups.intValue(); idx++) {
        for (int j = 0; j < numSerieForGroup.intValue(); j++) {
            try {
                String tmpSubCat = (String) subCategoryNames.get(j + idx * numSerieForGroup.intValue());
                map.mapKeyToGroup(tmpSubCat, "G" + (idx + 1));

            } catch (Exception e) {
                logger.error("out of range error in inserting in stacked bar group: continue anayway", e);
            }
        }
    }

    renderer.setSeriesToGroupMap(map);
    renderer.setItemMargin(0.0);
    renderer.setDrawBarOutline(false);
    renderer.setBaseItemLabelsVisible(true);
    if (percentageValue)
        renderer.setBaseItemLabelGenerator(
                new StandardCategoryItemLabelGenerator("{2}", new DecimalFormat("#,##.#%")));
    else
        renderer.setBaseItemLabelGenerator(new FilterZeroStandardCategoryItemLabelGenerator());
    renderer.setToolTipGenerator(new StandardCategoryToolTipGenerator());

    if (maxBarWidth != null) {
        renderer.setMaximumBarWidth(maxBarWidth.doubleValue());
    }

    boolean document_composition = false;
    if (mode.equalsIgnoreCase(SpagoBIConstants.DOCUMENT_COMPOSITION))
        document_composition = true;

    /*
    MyCategoryUrlGenerator mycatUrl=new MyCategoryUrlGenerator(rootUrl);
    mycatUrl.setDocument_composition(document_composition);
    mycatUrl.setCategoryUrlLabel(categoryUrlName);
    mycatUrl.setSerieUrlLabel(serieUrlname);
            
    renderer.setItemURLGenerator(mycatUrl);
     */

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

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...

    // set the background color for the chart...
    chart.setBackgroundPaint(color);

    NumberFormat nf = NumberFormat.getNumberInstance(locale);

    // set the range axis to display integers only...
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setLabelFont(new Font(styleXaxesLabels.getFontName(), Font.PLAIN, styleXaxesLabels.getSize()));
    rangeAxis.setLabelPaint(styleXaxesLabels.getColor());
    rangeAxis
            .setTickLabelFont(new Font(styleXaxesLabels.getFontName(), Font.PLAIN, styleXaxesLabels.getSize()));
    rangeAxis.setTickLabelPaint(styleXaxesLabels.getColor());
    rangeAxis.setNumberFormatOverride(nf);
    if (rangeIntegerValues == true) {
        rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    }
    if (rangeAxisLocation != null) {
        if (rangeAxisLocation.equalsIgnoreCase("BOTTOM_OR_LEFT")) {
            plot.setRangeAxisLocation(0, AxisLocation.BOTTOM_OR_LEFT);
        } else if (rangeAxisLocation.equalsIgnoreCase("BOTTOM_OR_RIGHT")) {
            plot.setRangeAxisLocation(0, AxisLocation.BOTTOM_OR_RIGHT);
        } else if (rangeAxisLocation.equalsIgnoreCase("TOP_OR_RIGHT")) {
            plot.setRangeAxisLocation(0, AxisLocation.TOP_OR_RIGHT);
        } else if (rangeAxisLocation.equalsIgnoreCase("TOP_OR_LEFT")) {
            plot.setRangeAxisLocation(0, AxisLocation.TOP_OR_LEFT);
        }
    }

    int seriesN = dataset.getRowCount();
    int numSerieColored = 0;

    if (orderColorVector != null && orderColorVector.size() > 0) {
        logger.debug("color serie by SERIES_ORDER_COLORS template specification");
        for (int i = 0; i < seriesN; i++) {
            if (orderColorVector.get(i) != null) {
                Color color = orderColorVector.get(i);
                renderer.setSeriesPaint(i, color);
            }
        }
    } else if (colorMap != null) {
        while (numSerieColored < seriesN) {
            for (int i = 1; i <= colorMap.size(); i++) {
                Color color = (Color) colorMap.get("SER" + i);
                Color gradient = new Color(Integer.decode("#FFFFFF").intValue());
                if (gradientMap != null)
                    gradient = (Color) gradientMap.get("SER" + i);

                if (color != null) {
                    Paint p = new GradientPaint(0.0f, 0.0f, color, 0.0f, 0.0f, gradient);

                    //renderer.setSeriesPaint(numSerieColored, color);
                    renderer.setSeriesPaint(numSerieColored, p);
                }
                numSerieColored++;
            }
        }
    }
    renderer.setGradientPaintTransformer(
            new StandardGradientPaintTransformer(GradientPaintTransformType.HORIZONTAL));

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

        double orient = (-Math.PI / 2.0);
        if (styleValueLabels.getOrientation().equalsIgnoreCase("horizontal")) {
            orient = 0.0;
        }
        renderer.setBaseItemLabelFont(
                new Font(styleValueLabels.getFontName(), Font.PLAIN, styleValueLabels.getSize()));
        renderer.setBaseItemLabelPaint(styleValueLabels.getColor());

        renderer.setBaseItemLabelGenerator(generator);
        renderer.setBaseItemLabelsVisible(true);
        //vertical labels          
        renderer.setBasePositiveItemLabelPosition(
                new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER, TextAnchor.CENTER, orient));
        renderer.setBaseNegativeItemLabelPosition(
                new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER, TextAnchor.CENTER, orient));

        //horizontal labels
        /*
        renderer.setBasePositiveItemLabelPosition(new ItemLabelPosition(
           ItemLabelAnchor.CENTER, TextAnchor.CENTER));
        renderer.setBaseNegativeItemLabelPosition(new ItemLabelPosition(
           ItemLabelAnchor.CENTER, TextAnchor.CENTER));
         */

    }

    SubCategoryAxis domainAxis = new SubCategoryAxis(categoryLabel + " / " + subCategoryLabel);
    String subCatLabel = "";
    for (int j = 1; j <= numGroups.intValue(); j++) {
        if (subCatLabelsMap != null)
            subCatLabel = (String) subCatLabelsMap.get("CAT" + j);
        else
            subCatLabel = subCategoryLabel;

        domainAxis.addSubCategory(subCatLabel);
        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());
    }
    plot.setDomainAxis(domainAxis);
    plot.setRenderer(renderer);

    /*
    domainAxis.setCategoryLabelPositions(
    CategoryLabelPositions.createUpRotationLabelPositions(
          Math.PI / 6.0));
     */
    if (legend == true)
        drawLegend(chart);
    logger.debug("OUT");
    return chart;

}

From source file:com.voterData.graph.Graph.java

public static JFreeChart getHLEthnicityDistbn(Map<String, Double> dataMap) {
    DefaultCategoryDataset defaultcategorydataset = new DefaultCategoryDataset();
    for (String key : dataMap.keySet()) {
        if (key.equals("HL_Dem_2008")) {
            defaultcategorydataset.addValue(dataMap.get(key), "DEM", "HL_2008");
        } else if (key.equals("HL_Rep_2008")) {
            defaultcategorydataset.addValue(dataMap.get(key), "REP", "HL_2008");
        } else if (key.equals("HL_Una_2008")) {
            defaultcategorydataset.addValue(dataMap.get(key), "UNA", "HL_2008");
        } else if (key.equals("HL_Dem_2012")) {
            defaultcategorydataset.addValue(dataMap.get(key), "DEM", "HL_2012");
        } else if (key.equals("HL_Rep_2012")) {
            defaultcategorydataset.addValue(dataMap.get(key), "REP", "HL_2012");
        } else if (key.equals("HL_Una_2012")) {
            defaultcategorydataset.addValue(dataMap.get(key), "UNA", "HL_2012");
        }//from w w  w . j  a v  a2s.co  m
    }

    JFreeChart jfreechart = ChartFactory.createStackedBarChart("Hispanic/Latino Distribution", "Ethnicity_Year",
            "Total Count", defaultcategorydataset, PlotOrientation.HORIZONTAL, true, true, false);
    jfreechart.setBackgroundPaint(Color.white);
    CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
    categoryplot.setBackgroundPaint(Color.lightGray);
    categoryplot.setRangeGridlinePaint(Color.white);
    StackedBarRenderer renderer = (StackedBarRenderer) categoryplot.getRenderer();

    renderer.setDrawBarOutline(false);
    renderer.setSeriesPaint(0, Color.red);
    renderer.setSeriesPaint(1, Color.blue);
    renderer.setSeriesPaint(2, Color.green);
    renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    renderer.setSeriesItemLabelGenerator(0, new StandardCategoryItemLabelGenerator());
    renderer.setItemLabelsVisible(true);
    categoryplot.setRenderer(renderer);

    return jfreechart;

}

From source file:eu.planets_project.tb.impl.chart.ExperimentChartServlet.java

public JFreeChart createWallclockChart(String expId) {
    ExperimentPersistencyRemote edao = ExperimentPersistencyImpl.getInstance();
    long eid = Long.parseLong(expId);
    log.info("Building experiment chart for eid = " + eid);
    Experiment exp = edao.findExperiment(eid);

    final DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    final String expName = exp.getExperimentSetup().getBasicProperties().getExperimentName();

    boolean hasSuccesses = false;
    boolean hasFails = false;

    for (BatchExecutionRecordImpl batch : exp.getExperimentExecutable().getBatchExecutionRecords()) {
        int i = 1;
        List<ExecutionRecordImpl> runs = new ArrayList<ExecutionRecordImpl>(batch.getRuns());
        Collections.sort(runs, new RunComparator());
        for (ExecutionRecordImpl exr : runs) {
            //log.info("Found Record... "+exr+" stages: "+exr.getStages());
            if (exr != null && exr.getStages() != null) {
                // Look up the object, so we can get the name.
                DigitalObjectRefBean dh = new DataHandlerImpl().get(exr.getDigitalObjectReferenceCopy());
                String dobName = "Object " + i;
                if (dh != null)
                    dobName = dh.getName();

                ResultsForDigitalObjectBean res = new ResultsForDigitalObjectBean(
                        exr.getDigitalObjectReferenceCopy());
                Double time = null;
                boolean success = false;
                // First, attempt to pull from stage records:
                // FIXME: Note that this record is really at the wrong level.
                /*// w  w w.j a  v  a  2  s . co m
                if( exr.getStages().size() == 1 ) {
                for( ExecutionStageRecordImpl exsr : exr.getStages() ) {
                    Double stageTime = exsr.getDoubleMeasurement( TecRegMockup.PROP_SERVICE_TIME );
                    if( stageTime != null ) {
                        time = stageTime;
                        success = exsr.isMarkedAsSuccessful();
                    }
                }
                }
                */
                // Pick up from record duration:
                if (time == null && res.getExecutionDuration() != null) {
                    //convert from milli seconds to seconds
                    time = (double) res.getExecutionDuration() / 1000.0;
                    success = res.getHasExecutionSucceededOK();
                }
                log.info("Found DOB: {" + exr.getDigitalObjectReferenceCopy() + "} {" + dobName + "} w/ time "
                        + time);
                if (res.getExecutionRecord() != null)
                    log.info("Timing: " + res.getExecutionRecord().getStartDate() + " "
                            + res.getExecutionRecord().getEndDate());
                if (time != null) {
                    if (success) {
                        dataset.addValue(time, "Succeeded", dobName);
                        hasSuccesses = true;
                    } else {
                        dataset.addValue(time, "Failed", dobName);
                        hasFails = true;
                    }
                }
            }
            // Increment, for the next run.
            i++;
        }
    }
    int si = dataset.getRowIndex("Succeeded");
    int ri = dataset.getRowIndex("Failed");

    // Create the chart.
    JFreeChart chart = ChartFactory.createStackedBarChart(null, "Digital Object", "Time [s]", dataset,
            PlotOrientation.VERTICAL, true, true, false);

    // set the background color for the chart...
    chart.setBackgroundPaint(Color.white);

    // get a reference to the plot for further customisation...
    final CategoryPlot plot = chart.getCategoryPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.gray);
    plot.setRangeGridlinePaint(Color.gray);

    // set the range axis to display integers only...
    //final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    //rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    // disable bar outlines...
    final BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(true);
    renderer.setShadowVisible(false);
    renderer.setBarPainter(new StandardBarPainter());

    // set up gradient paints for series...
    final GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f,
            new Color(0.0f, 0.9f, 0.0f));
    final GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, new Color(0.9f, 0.0f, 0.0f));
    if (hasSuccesses)
        renderer.setSeriesPaint(si, gp0);
    if (hasFails)
        renderer.setSeriesPaint(ri, gp1);

    // Set the tooltips...
    //renderer.setBaseItemURLGenerator(new StandardCategoryURLGenerator("xy_chart.jsp","series","section"));
    renderer.setBaseToolTipGenerator(new MeasurementToolTipGenerator());

    final CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 4.0));

    // More settings
    chart.getRenderingHints().put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    // Remove the border, as the SVG renderer has problems with the text overflowing.
    chart.getLegend().setBorder(0.0, 0.0, 0.0, 0.0);
    // Remove the padding between the axes and the plot:
    chart.getPlot().setInsets(new RectangleInsets(0.0, 0.0, 0.0, 0.0));
    // Set a gradient fill, fading towards the top:
    final GradientPaint gpb0 = new GradientPaint(0.0f, 0.0f, new Color(245, 245, 245), 0.0f, 0.0f, Color.white);
    chart.getPlot().setBackgroundPaint(gpb0);

    return chart;
}

From source file:com.rapidminer.gui.plotter.charts.StackedBarChartPlotter.java

@Override
public void updatePlotter() {
    final int categoryCount = prepareData();

    if (categoryCount <= MAX_CATEGORIES) {
        JFreeChart chart = ChartFactory.createStackedBarChart(null, // chart title
                null, // domain axis label
                null, // range axis label
                categoryDataSet, // usedCategoryDataSet, // data
                orientationIndex == ORIENTATION_TYPE_VERTICAL ? PlotOrientation.VERTICAL
                        : PlotOrientation.HORIZONTAL, // orientation
                true, // include legend if group by column is set
                true, // tooltips
                false // URLs
        );//ww w  .  j a v  a  2 s.  com

        // set the background color for the chart...
        chart.setBackgroundPaint(Color.WHITE);
        chart.getPlot().setBackgroundPaint(Color.WHITE);

        CategoryPlot plot = chart.getCategoryPlot();
        plot.setDomainGridlinePaint(Color.LIGHT_GRAY);
        plot.setRangeGridlinePaint(Color.LIGHT_GRAY);

        CategoryAxis domainAxis = plot.getDomainAxis();
        domainAxis.setLabelFont(LABEL_FONT_BOLD);
        domainAxis.setTickLabelFont(LABEL_FONT);
        String domainName = groupByColumn >= 0 ? dataTable.getColumnName(groupByColumn) : null;
        domainAxis.setLabel(domainName);

        // rotate labels
        if (isLabelRotating()) {
            plot.getDomainAxis().setTickLabelsVisible(true);
            plot.getDomainAxis().setCategoryLabelPositions(
                    CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 2.0d));
        }

        // set the range axis to display integers only...
        NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
        rangeAxis.setLabelFont(LABEL_FONT_BOLD);
        rangeAxis.setTickLabelFont(LABEL_FONT);
        String rangeName = valueColumn >= 0 ? dataTable.getColumnName(valueColumn) : null;
        rangeAxis.setLabel(rangeName);

        // bar renderer
        int length = 0;
        // if ((groupByColumn >= 0) && this.dataTable.isNominal(groupByColumn)) {
        // length = this.dataTable.getNumberOfValues(groupByColumn);
        // } else {
        // length = categoryDataSet.getColumnCount();
        // }
        if (stackGroupColumn >= 0 && this.dataTable.isNominal(stackGroupColumn)) {
            length = this.dataTable.getNumberOfValues(stackGroupColumn);
        } else {
            length = categoryDataSet.getRowCount();
        }
        final double[] colorValues = new double[length];
        for (int i = 0; i < colorValues.length; i++) {
            colorValues[i] = i;
        }
        BarRenderer renderer = new StackedBarRenderer() {

            private static final long serialVersionUID = 1912387984078591157L;

            private ColorProvider colorProvider = getColorProvider(true);

            private double minColor = Double.POSITIVE_INFINITY;
            private double maxColor = Double.NEGATIVE_INFINITY;
            {
                if (colorValues != null) {
                    for (double d : colorValues) {
                        this.minColor = MathFunctions.robustMin(this.minColor, d);
                        this.maxColor = MathFunctions.robustMax(this.maxColor, d);
                    }
                }
            }

            @Override
            public Paint getSeriesPaint(int series) {
                if (colorValues == null || minColor == maxColor || series >= colorValues.length) {
                    return ColorProvider.reduceColorBrightness(Color.RED);
                } else {
                    double normalized = (colorValues[series] - minColor) / (maxColor - minColor);
                    return colorProvider.getPointColor(normalized);
                }
            }
        };

        renderer.setBarPainter(new RapidBarPainter());
        renderer.setDrawBarOutline(true);
        renderer.setShadowVisible(false);
        plot.setRenderer(renderer);

        // legend settings
        LegendTitle legend = chart.getLegend();
        if (legend != null) {
            legend.setPosition(RectangleEdge.TOP);
            legend.setFrame(BlockBorder.NONE);
            legend.setHorizontalAlignment(HorizontalAlignment.LEFT);
            legend.setItemFont(LABEL_FONT);
        }

        if (panel instanceof AbstractChartPanel) {
            panel.setChart(chart);
        } else {
            panel = new AbstractChartPanel(chart, getWidth(), getHeight() - MARGIN);
            final ChartPanelShiftController controller = new ChartPanelShiftController(panel);
            panel.addMouseListener(controller);
            panel.addMouseMotionListener(controller);
        }

        // ATTENTION: WITHOUT THIS WE GET SEVERE MEMORY LEAKS!!!
        panel.getChartRenderingInfo().setEntityCollection(null);
    } else {
        LogService.getRoot().log(Level.INFO,
                "com.rapidminer.gui.plotter.charts.StackedBarChartPlotter.too_many_columns",
                new Object[] { categoryCount, MAX_CATEGORIES });
    }
}

From source file:org.adempiere.apps.graph.ChartBuilder.java

private JFreeChart createStackedBarChart() {
    JFreeChart chart = ChartFactory.createStackedBarChart(chartModel.get_Translation(MChart.COLUMNNAME_Name), // chart title
            chartModel.get_Translation(MChart.COLUMNNAME_DomainLabel), // domain axis label
            chartModel.get_Translation(MChart.COLUMNNAME_RangeLabel), // range axis label
            getCategoryDataset(), // data
            X_AD_Chart.CHARTORIENTATION_Horizontal.equals(chartModel.getChartOrientation())
                    ? PlotOrientation.HORIZONTAL
                    : PlotOrientation.VERTICAL, // orientation
            chartModel.isDisplayLegend(), // include legend
            true, // tooltips?
            true // URLs?
    );//from w  w w  .  j  a  va  2  s.  c o  m

    BarRenderer renderer = new BarRenderer();
    renderer.setBarPainter(new StandardBarPainter());

    CategoryPlot plot = chart.getCategoryPlot();
    plot.setRenderer(renderer);

    setupCategoryChart(chart);
    return chart;
}

From source file:Simulator.PerformanceCalculation.java

public JPanel cost2() {

    CategoryDataset dataset = createDataset();
    JFreeChart stackedChart = ChartFactory.createStackedBarChart("Cost", "Surgeon ID", "$", dataset,
            PlotOrientation.VERTICAL, true, true, false);
    String series1 = "Cost for Actual Wait";
    String series2 = "Cost for Minimum Wait";
    String series3 = "Cost for Acceptable Wait";

    //create group 
    GroupedStackedBarRenderer renderer = new GroupedStackedBarRenderer();
    KeyToGroupMap map = new KeyToGroupMap("G1");
    map.mapKeyToGroup(series1, "G1");
    map.mapKeyToGroup(series2, "G1");
    map.mapKeyToGroup(series3, "G1");

    renderer.setSeriesToGroupMap(map);/*from  ww w .  j a  v  a 2  s . c  om*/
    renderer.setItemMargin(0.03);

    Color red = new Color(255, 128, 0);
    Color green = new Color(0, 128, 0);
    Color yellow = new Color(165, 227, 17);

    renderer.setSeriesPaint(2, Color.RED);
    renderer.setSeriesPaint(1, yellow);
    renderer.setSeriesPaint(0, green);

    CategoryPlot plot = (CategoryPlot) stackedChart.getPlot();
    plot.setRenderer(renderer);

    return new ChartPanel(stackedChart);
}