Example usage for org.jfree.chart.renderer.category StackedBarRenderer setBarPainter

List of usage examples for org.jfree.chart.renderer.category StackedBarRenderer setBarPainter

Introduction

In this page you can find the example usage for org.jfree.chart.renderer.category StackedBarRenderer setBarPainter.

Prototype

public void setBarPainter(BarPainter painter) 

Source Link

Document

Sets the bar painter for this renderer and sends a RendererChangeEvent to all registered listeners.

Usage

From source file:org.fhaes.fhrecorder.util.ColorBar.java

/**
 * Creates a chart when given a data set.
 * /*from   www .  j a  v  a2s .  c om*/
 * @param dataset to be plotted.
 * @return the created chart.
 */
private static JFreeChart createChart(final CategoryDataset dataset) {

    final JFreeChart chart = ChartFactory.createStackedBarChart("", "", "", dataset, PlotOrientation.HORIZONTAL,
            false, true, false);

    chart.setPadding(RectangleInsets.ZERO_INSETS);
    chart.setBorderVisible(false);

    StackedBarRenderer renderer = new StackedBarRenderer();
    renderer.setBarPainter(new StandardBarPainter()); // Remove shine
    renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
    renderer.setShadowVisible(false);

    CategoryPlot plot = chart.getCategoryPlot();
    plot.setRenderer(renderer);
    // plot.setBackgroundAlpha(0.0f);

    plot.setDomainGridlinesVisible(false);
    plot.setRangeGridlinesVisible(false);

    plot.getRangeAxis().setVisible(false);
    plot.getRangeAxis().setLowerMargin(0);
    plot.getRangeAxis().setUpperMargin(0);

    plot.getDomainAxis().setVisible(false);
    plot.getDomainAxis().setLowerMargin(0);
    plot.getDomainAxis().setUpperMargin(0);

    return chart;
}

From source file:org.fhaes.fhrecorder.view.ColorBarGraph.java

/**
 * Creates the chart with the data from the given data set.
 * //from  w ww  . j a va  2 s. com
 * @param dataset the data to plot.
 * @return the chart.
 */
private static JFreeChart createChart(final CategoryDataset dataset) {

    final JFreeChart chart = ChartFactory.createStackedBarChart("", "", "", dataset, PlotOrientation.VERTICAL,
            false, true, false);

    StackedBarRenderer renderer = new StackedBarRenderer(true);
    renderer.setShadowVisible(false);
    renderer.setBarPainter(new StandardBarPainter()); // Remove shine
    renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());

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

    plot.setBackgroundPaint(Color.WHITE);
    plot.setDomainGridlinesVisible(true);
    plot.setDomainGridlinePaint(new Color(192, 192, 192));

    plot.getDomainAxis().setTickLabelFont(new Font("SansSerif", Font.PLAIN, 12));
    plot.getDomainAxis().setVisible(false);
    plot.getRangeAxis().setVisible(false);
    plot.getDomainAxis().setLowerMargin(.025);
    plot.getDomainAxis().setUpperMargin(.025);

    chart.setBackgroundPaint(new Color(214, 217, 233, 30));

    return chart;
}

From source file:edu.jhuapl.graphs.jfreechart.JFreeChartStackedBarGraphSource.java

@Override
public JFreeChart createChart(String title, String xLabel, String yLabel, CategoryDataset dataset,
        boolean legend, boolean graphToolTip) {
    PlotOrientation orientation = getParam(PLOT_ORIENTATION, PlotOrientation.class, DEFAULT_PLOT_ORIENTATION);
    JFreeChart result = ChartFactory.createBarChart(title, xLabel, yLabel, dataset, orientation, legend,
            graphToolTip, false);//from   w ww.j  a  va 2s .  c o  m
    StackedBarRenderer renderer = new CategoryStackedBarGraphRenderer(data);

    renderer.setShadowVisible(false);
    renderer.setBarPainter(new CategoryGraphBarPainter(data));
    result.getCategoryPlot().setRenderer(renderer);

    return result;
}

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

/**
 * Create a chart from the provided category dataset
 * @return a Chart that can be rendered in a ChartPanel
 *///from   www  .  j av a2 s.com
@Override
protected JFreeChart createChart() {
    //Create a vertical 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.VERTICAL, true, true, false);
    //Get the font from the platform UI
    Font chartFont = UIManager.getFont("Label.font");
    //Get the plot from the chart
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    //Get the renderer from the plot
    StackedBarRenderer sbRenderer = (StackedBarRenderer) plot.getRenderer();
    //Set the rendered to use a standard bar painter (nothing fancy)
    sbRenderer.setBarPainter(new StandardBarPainter());
    //Set the colours for the bars
    sbRenderer.setSeriesPaint(0, PREPARATION_COLOR);
    sbRenderer.setSeriesPaint(1, SUPPORT_COLOR);
    //Set the tooltip to be series, category and value
    sbRenderer.setBaseToolTipGenerator(
            new StandardCategoryToolTipGenerator("{0}, {1} ({2})", NumberFormat.getInstance()));
    //Get the category axis (that's the X-axis in this case)
    CategoryAxis categoryAxis = plot.getDomainAxis();
    //Set the font for rendering the labels on the x-axis to be the platform default
    categoryAxis.setLabelFont(chartFont);
    //Get the number axis (that's the Y-axis in this case)
    NumberAxis numberAxis = (NumberAxis) plot.getRangeAxis();
    //Use the same font as the x-axis
    numberAxis.setLabelFont(chartFont);
    return chart;
}

From source file:de.mpg.mpdl.inge.pubman.web.statistic_charts.StatisticChartServlet.java

/**
 * Creates the statistic chart.// www.ja v a2  s.  c  o m
 * 
 * @param dataset the dataset.
 * 
 * @return The chart.
 */
private JFreeChart createChart(CategoryDataset dataset) {

    // create the chart
    JFreeChart chart = ChartFactory.createStackedBarChart(null, // chart title
            "", // domain axis label
            "", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            false, // tooltips?
            false // URLs?
    );

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

    // get a reference to the plot for further customisation
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setBackgroundPaint(new Color(0xf5, 0xf5, 0xf5));
    plot.setDomainGridlinePaint(Color.gray);
    plot.setDomainGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.gray);

    // set the range axis to display integers only
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setLowerBound(0);
    // disable bar outlines...
    StackedBarRenderer renderer = (StackedBarRenderer) plot.getRenderer();
    renderer.setBarPainter(new StandardBarPainter());
    renderer.setDrawBarOutline(false);

    // set up gradient paints for series
    /*
     * GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, new Color(0, 0,
     * 64)); GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, new Color(64,
     * 0, 0));
     */
    Color series1Color = new Color(0xfa, 0x80, 0x72);
    Color series2Color = new Color(0x64, 0x95, 0xed);
    renderer.setSeriesPaint(1, series1Color);
    renderer.setSeriesPaint(0, series2Color);

    // remove shadow
    renderer.setShadowVisible(false);
    //

    // Labels in bars
    /*
     * renderer.setSeriesItemLabelsVisible(0, true); renderer.setSeriesItemLabelGenerator(0, new
     * StandardCategoryItemLabelGenerator()); renderer.setSeriesItemLabelPaint(0, Color.white);
     * renderer.setSeriesItemLabelsVisible(1, true); renderer.setSeriesItemLabelGenerator(1, new
     * StandardCategoryItemLabelGenerator()); renderer.setSeriesItemLabelPaint(1, Color.white);
     */

    // setCategorySummary(dataset);

    // rotate labels on x-axis
    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0));

    return chart;

}

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
 *//*from www  .j av  a2  s  . com*/
@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:de.mpg.escidoc.pubman.statistic_charts.StatisticChartServlet.java

/**
 * Creates the statistic chart./*  w w w .ja  v  a 2 s.  co m*/
 *
 * @param dataset  the dataset.
 *
 * @return The chart.
 */
private JFreeChart createChart(CategoryDataset dataset) {

    // create the chart
    JFreeChart chart = ChartFactory.createStackedBarChart(null, // chart title
            "", // domain axis label
            "", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            false, // tooltips?
            false // URLs?
    );

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

    // get a reference to the plot for further customisation
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setBackgroundPaint(new Color(0xf5, 0xf5, 0xf5));
    plot.setDomainGridlinePaint(Color.gray);
    plot.setDomainGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.gray);

    // set the range axis to display integers only
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setLowerBound(0);
    // disable bar outlines...
    StackedBarRenderer renderer = (StackedBarRenderer) plot.getRenderer();
    renderer.setBarPainter(new StandardBarPainter());
    renderer.setDrawBarOutline(false);

    // set up gradient paints for series
    /*
    GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue,
        0.0f, 0.0f, new Color(0, 0, 64));
    GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.red,
        0.0f, 0.0f, new Color(64, 0, 0));
    */
    Color series1Color = new Color(0xfa, 0x80, 0x72);
    Color series2Color = new Color(0x64, 0x95, 0xed);
    renderer.setSeriesPaint(1, series1Color);
    renderer.setSeriesPaint(0, series2Color);

    //remove shadow
    renderer.setShadowVisible(false);
    //

    //Labels in bars
    /*
    renderer.setSeriesItemLabelsVisible(0, true);
    renderer.setSeriesItemLabelGenerator(0, new StandardCategoryItemLabelGenerator());
    renderer.setSeriesItemLabelPaint(0, Color.white);
    renderer.setSeriesItemLabelsVisible(1, true);
    renderer.setSeriesItemLabelGenerator(1, new StandardCategoryItemLabelGenerator());
    renderer.setSeriesItemLabelPaint(1, Color.white);
      */

    //setCategorySummary(dataset);

    //rotate labels on x-axis
    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0));

    return chart;

}