Example usage for org.jfree.chart ChartFactory createBarChart

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

Introduction

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

Prototype

public static JFreeChart createBarChart(String title, String categoryAxisLabel, String valueAxisLabel,
        CategoryDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls) 

Source Link

Document

Creates a bar chart.

Usage

From source file:herramientas.Ecualizacion_histograma.java

public void histogramaAcumulativo() {
    JFrame vHist = new JFrame("Histograma Acumulado");

    JFreeChart graf_hist = null;/*from  w  w  w.j  a  va  2 s. c  om*/

    DefaultCategoryDataset data = new DefaultCategoryDataset();

    int datosAc[] = new int[256];

    for (int i = 0; i < 256; i++) {
        datosAc[i] = 0;
    }

    datosAc[0] = datos[0];
    for (int i = 1; i < 256; i++) {
        datosAc[i] = datos[i] + datosAc[i - 1];
    }

    for (int i = 0; i < 256; i++) {
        //            if(datos[i] != 0) //Mostrando solo los que son distintos de 0.
        data.addValue(datosAc[i], "Histograma frec. abs. ac.", Integer.toString(i));
    }

    graf_hist = ChartFactory.createBarChart("Histograma de frecuencias absolutas acumuladas", "Nivel RGB",
            "Nmero de pxeles", data, PlotOrientation.VERTICAL, false, false, false);

    ChartPanel panel = new ChartPanel(graf_hist);
    vHist.getContentPane().add(panel);
    vHist.pack();
    vHist.setVisible(true);

}

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

public JFreeChart createChart(DatasetMap datasets) {
    logger.debug("IN");
    CategoryDataset dataset = (CategoryDataset) datasets.getDatasets().get("1");

    PlotOrientation plotOrientation = PlotOrientation.VERTICAL;
    if (horizontalView) {
        plotOrientation = PlotOrientation.HORIZONTAL;
    }//from w w  w . ja v  a 2 s .c om

    JFreeChart chart = ChartFactory.createBarChart(name, // chart title
            categoryLabel, // domain axis label
            valueLabel, // range axis label
            dataset, // data
            plotOrientation, // orientation
            false, // include legend
            true, // tooltips?
            false // URLs?
    );

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

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

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

    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.setUpperMargin(0.10);
    rangeAxis.setNumberFormatOverride(nf);

    if (firstAxisLB != null && firstAxisUB != null) {
        rangeAxis.setLowerBound(firstAxisLB);
        rangeAxis.setUpperBound(firstAxisUB);
    }

    if (rangeIntegerValues == true) {
        rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    } else
        rangeAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits());

    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);
        }
    }

    // disable bar outlines...
    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);

    // add
    CategorySeriesLabelGenerator generator = new StandardCategorySeriesLabelGenerator("{0}");
    renderer.setLegendItemLabelGenerator(generator);

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

    if (showValueLabels) {
        renderer.setBaseItemLabelsVisible(true);
        renderer.setBaseItemLabelGenerator(new FilterZeroStandardCategoryItemLabelGenerator());
        renderer.setBaseItemLabelFont(
                new Font(styleValueLabels.getFontName(), Font.PLAIN, styleValueLabels.getSize()));
        renderer.setBaseItemLabelPaint(styleValueLabels.getColor());

        //         if(valueLabelsPosition.equalsIgnoreCase("inside")){
        //         renderer.setBasePositiveItemLabelPosition(new ItemLabelPosition(
        //         ItemLabelAnchor.CENTER, TextAnchor.BASELINE_LEFT));
        //         renderer.setBaseNegativeItemLabelPosition(new ItemLabelPosition(
        //         ItemLabelAnchor.CENTER, TextAnchor.BASELINE_LEFT));
        //         } else {
        //         renderer.setBasePositiveItemLabelPosition(new ItemLabelPosition(
        //         ItemLabelAnchor.OUTSIDE3, TextAnchor.BASELINE_LEFT));
        //         renderer.setBaseNegativeItemLabelPosition(new ItemLabelPosition(
        //         ItemLabelAnchor.OUTSIDE3, TextAnchor.BASELINE_LEFT));
        //         }

    }

    // PROVA LEGENDA      
    if (legend == true) {

        drawLegend(chart);

        /*BlockContainer wrapper = new BlockContainer(new BorderArrangement());
        wrapper.setFrame(new BlockBorder(1.0, 1.0, 1.0, 1.0));
                
        LabelBlock titleBlock = new LabelBlock("Legend Items:",
              new Font("SansSerif", Font.BOLD, 12));
        title.setPadding(5, 5, 5, 5);
        wrapper.add(titleBlock, RectangleEdge.TOP);
                
        LegendTitle legend = new LegendTitle(chart.getPlot());
        BlockContainer items = legend.getItemContainer();
        items.setPadding(2, 10, 5, 2);
        wrapper.add(items);
        legend.setWrapper(wrapper);
                
        if(legendPosition.equalsIgnoreCase("bottom")) legend.setPosition(RectangleEdge.BOTTOM);
        else if(legendPosition.equalsIgnoreCase("left")) legend.setPosition(RectangleEdge.LEFT);
        else if(legendPosition.equalsIgnoreCase("right")) legend.setPosition(RectangleEdge.RIGHT);
        else if(legendPosition.equalsIgnoreCase("top")) legend.setPosition(RectangleEdge.TOP);
        else legend.setPosition(RectangleEdge.BOTTOM);
                
        legend.setHorizontalAlignment(HorizontalAlignment.LEFT);
        chart.addSubtitle(legend);*/
    }

    int seriesN = dataset.getRowCount();

    // the order color vedctor overrides the color map!!

    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) {
        logger.debug("color serie by SERIES_COLORS template specification");
        for (int i = 0; i < seriesN; i++) {
            String serieName = (String) dataset.getRowKey(i);
            String labelName = "";
            int index = -1;
            if (seriesCaptions != null && seriesCaptions.size() > 0) {
                labelName = serieName;
                serieName = (String) seriesCaptions.get(serieName);
                index = dataset.getRowIndex(labelName);
            } else
                index = dataset.getRowIndex(serieName);

            Color color = (Color) colorMap.get(serieName);
            if (color != null) {
                //renderer.setSeriesPaint(i, color);
                renderer.setSeriesPaint(index, color);
                renderer.setSeriesItemLabelFont(i,
                        new Font(defaultLabelsStyle.getFontName(), Font.PLAIN, defaultLabelsStyle.getSize()));
                renderer.setSeriesItemLabelPaint(i, defaultLabelsStyle.getColor());
            }
        }
    }

    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0));
    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);
    logger.debug("OUT");
    return chart;

}

From source file:ch.opentrainingcenter.charts.bar.OTCCategoryChartViewer.java

JFreeChart createChart() {
    chart = ChartFactory.createBarChart("", "", "", dataset, PlotOrientation.VERTICAL, false, true, false); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    chart.setAntiAlias(true);/*w  w w . j  a v a 2  s. c  o  m*/
    chart.setBorderVisible(false);
    chart.setAntiAlias(true);
    chart.setBorderVisible(true);
    chart.setTextAntiAlias(true);
    chart.setBackgroundPaint(Color.white);
    chart.setBorderPaint(Color.white);

    //
    final CategoryPlot plot = chart.getCategoryPlot();
    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinePaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.lightGray);
    return chart;
}

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

/**
 * Creates a new demo.//from  w  w w .ja v  a  2s.  co  m
 *
 * @param title  the frame title.
 */
public MinMaxCategoryPlotDemo(final String title) {

    super(title);

    // create a dataset...
    final DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    dataset.addValue(1.0, "First", "Category 1");
    dataset.addValue(4.0, "First", "Category 2");
    dataset.addValue(3.0, "First", "Category 3");
    dataset.addValue(5.0, "First", "Category 4");
    dataset.addValue(5.0, "First", "Category 5");
    dataset.addValue(7.0, "First", "Category 6");
    dataset.addValue(7.0, "First", "Category 7");
    dataset.addValue(8.0, "First", "Category 8");
    dataset.addValue(5.0, "Second", "Category 1");
    dataset.addValue(7.0, "Second", "Category 2");
    dataset.addValue(6.0, "Second", "Category 3");
    dataset.addValue(8.0, "Second", "Category 4");
    dataset.addValue(4.0, "Second", "Category 5");
    dataset.addValue(4.0, "Second", "Category 6");
    dataset.addValue(2.0, "Second", "Category 7");
    dataset.addValue(1.0, "Second", "Category 8");
    dataset.addValue(4.0, "Third", "Category 1");
    dataset.addValue(3.0, "Third", "Category 2");
    dataset.addValue(2.0, "Third", "Category 3");
    dataset.addValue(3.0, "Third", "Category 4");
    dataset.addValue(6.0, "Third", "Category 5");
    dataset.addValue(3.0, "Third", "Category 6");
    dataset.addValue(4.0, "Third", "Category 7");
    dataset.addValue(3.0, "Third", "Category 8");

    // create the chart...
    final JFreeChart chart = ChartFactory.createBarChart("Min/Max Category Plot", // chart title
            "Category", // domain axis label
            "Value", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips
            false // urls
    );

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

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

    // get a reference to the plot for further customisation...
    final CategoryPlot plot = chart.getCategoryPlot();
    plot.setRenderer(new MinMaxCategoryRenderer());
    // OPTIONAL CUSTOMISATION COMPLETED.

    // add the chart to a panel...
    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    setContentPane(chartPanel);

}

From source file:com.att.aro.ui.view.overviewtab.TraceBenchmarkChartPanel.java

private JFreeChart initializeChart() {

    JFreeChart chart = ChartFactory.createBarChart(
            ResourceBundleHelper.getMessageString("overview.traceoverview.title"), null, null, createDataset(),
            PlotOrientation.HORIZONTAL, false, true, false);
    chart.setBackgroundPaint(this.getBackground());
    chart.getTitle().setFont(AROUIManager.HEADER_FONT);

    this.plot = chart.getCategoryPlot();
    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinePaint(Color.gray);
    plot.setRangeGridlinePaint(Color.gray);
    plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_RIGHT);

    CategoryAxis valueRangeAxis = plot.getDomainAxis();
    valueRangeAxis.setMaximumCategoryLabelWidthRatio(1.0f);
    valueRangeAxis.setMaximumCategoryLabelLines(2);
    valueRangeAxis.setLabelFont(AROUIManager.LABEL_FONT);
    valueRangeAxis.setTickLabelFont(AROUIManager.LABEL_FONT);

    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setLabel(ResourceBundleHelper.getMessageString("analysisresults.percentile"));
    rangeAxis.setRange(0.0, 100.0);// w ww .j a  v a2s . c o  m
    rangeAxis.setTickUnit(new NumberTickUnit(10));
    rangeAxis.setLabelFont(AROUIManager.LABEL_FONT);
    rangeAxis.setTickLabelFont(AROUIManager.LABEL_FONT);

    BarRenderer renderer = new StackedBarRenderer();
    renderer.setBasePaint(AROUIManager.CHART_BAR_COLOR);
    renderer.setAutoPopulateSeriesPaint(false);
    renderer.setBaseItemLabelGenerator(new PercentLabelGenerator());
    renderer.setBaseItemLabelsVisible(true);
    renderer.setBaseItemLabelPaint(Color.black);

    // Make second bar in stack invisible
    renderer.setSeriesItemLabelsVisible(1, false);
    renderer.setSeriesPaint(1, new Color(0, 0, 0, 0));

    ItemLabelPosition insideItemlabelposition = new ItemLabelPosition(ItemLabelAnchor.INSIDE3,
            TextAnchor.CENTER_RIGHT);
    renderer.setBasePositiveItemLabelPosition(insideItemlabelposition);

    ItemLabelPosition outsideItemlabelposition = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE3,
            TextAnchor.CENTER_LEFT);
    renderer.setPositiveItemLabelPositionFallback(outsideItemlabelposition);

    renderer.setBarPainter(new StandardBarPainter());
    renderer.setShadowVisible(false);
    renderer.setMaximumBarWidth(BAR_WIDTH_PERCENT);
    renderer.setBaseToolTipGenerator(new CategoryToolTipGenerator() {
        @Override
        public String generateToolTip(CategoryDataset arg0, int arg1, int arg2) {
            String traceInfo = "";
            switch (arg2) {
            case TRACE_AVERAGE:
                traceInfo = ResourceBundleHelper.getMessageString("tooltip.traceAnalysis.avg");
                break;
            case TRACE_ENERGY:
                traceInfo = ResourceBundleHelper.getMessageString("tooltip.traceAnalysis.engy");
                break;
            case TRACE_OVERHEAD:
                traceInfo = ResourceBundleHelper.getMessageString("tooltip.traceAnalysis.ovrhd");
                break;
            default:
                break;
            }

            return traceInfo;
        }
    });

    plot.setRenderer(renderer);
    plot.getDomainAxis().setMaximumCategoryLabelLines(2);

    return chart;

}

From source file:org.pentaho.chart.plugin.jfreechart.chart.multi.JFreeMultiChartGenerator.java

public JFreeChart createChart(final ChartDocumentContext chartDocContext, final ChartTableModel data,
        final CSSConstant chartType) {
    final ChartDocument chartDocument = chartDocContext.getChartDocument();
    final String title = getTitle(chartDocument);
    final String valueCategoryLabel = getValueCategoryLabel(chartDocument);
    final String valueAxisLabel = getValueAxisLabel(chartDocument);
    final PlotOrientation orientation = getPlotOrientation(chartDocument);
    final boolean legend = getShowLegend(chartDocument);
    final boolean toolTips = getShowToolTips(chartDocument);

    final DefaultCategoryDataset categoryDataset = datasetGeneratorFactory
            .createDefaultCategoryDataset(chartDocContext, data);
    if (categoryDataset == null) {
        logger.error(Messages.getErrorString("JFreeChartFactoryEngine.ERROR_0001_DATASET_IS_NULL")); //$NON-NLS-1$
        return null;
    }//from   w w w.  j a  v a2 s.  c om

    JFreeChart chart = null;
    if (ChartMultiStyle.MULTI.equals(chartType)) {

        chart = ChartFactory.createBarChart(title, valueCategoryLabel, valueAxisLabel, categoryDataset,
                orientation, legend, toolTips, true);

        CategoryPlot plot = (CategoryPlot) chart.getPlot();

        DefaultCategoryDataset dataset1 = categoryDataset;
        plot.setDataset(1, dataset1);

        DefaultCategoryDataset dataset2 = categoryDataset;
        plot.setDataset(2, dataset2);

        LineAndShapeRenderer renderer1 = new LineAndShapeRenderer();
        renderer1.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
        plot.setRenderer(1, renderer1);
        plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

        AreaRenderer renderer2 = new AreaRenderer();
        renderer2.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
        plot.setRenderer(2, renderer2);
        plot.setDatasetRenderingOrder(DatasetRenderingOrder.REVERSE);

    }

    final CategoryPlot categoryPlot = chart.getCategoryPlot();
    final ChartElement[] seriesElements = chartDocument.getRootElement()
            .findChildrenByName(ChartElement.TAG_NAME_SERIES);
    if (categoryPlot != null && seriesElements != null) {
        setSeriesAttributes(seriesElements, data, categoryPlot);
    }

    return chart;
}

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

/**
 * Creates a new demo./*from  ww  w.  jav a2s  .  com*/
 *
 * @param title  the frame title.
 */
public EventFrequencyDemo(final String title) {

    super(title);

    // create a dataset...
    final DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    // initialise the data...
    final Day d1 = new Day(12, SerialDate.JUNE, 2002);
    final Day d2 = new Day(14, SerialDate.JUNE, 2002);
    final Day d3 = new Day(15, SerialDate.JUNE, 2002);
    final Day d4 = new Day(10, SerialDate.JULY, 2002);
    final Day d5 = new Day(20, SerialDate.JULY, 2002);
    final Day d6 = new Day(22, SerialDate.AUGUST, 2002);

    dataset.setValue(new Long(d1.getMiddleMillisecond()), "Series 1", "Requirement 1");
    dataset.setValue(new Long(d1.getMiddleMillisecond()), "Series 1", "Requirement 2");
    dataset.setValue(new Long(d2.getMiddleMillisecond()), "Series 1", "Requirement 3");
    dataset.setValue(new Long(d3.getMiddleMillisecond()), "Series 2", "Requirement 1");
    dataset.setValue(new Long(d4.getMiddleMillisecond()), "Series 2", "Requirement 3");
    dataset.setValue(new Long(d5.getMiddleMillisecond()), "Series 3", "Requirement 2");
    dataset.setValue(new Long(d6.getMiddleMillisecond()), "Series 1", "Requirement 4");

    // create the chart...
    final JFreeChart chart = ChartFactory.createBarChart("Event Frequency Demo", // title
            "Category", // domain axis label
            "Value", // range axis label
            dataset, // dataset
            PlotOrientation.HORIZONTAL, // orientation
            true, // include legend
            true, // tooltips
            false // URLs
    );

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

    // set the background color for the chart...
    chart.setBackgroundPaint(new Color(0xFF, 0xFF, 0xCC));

    //        final StandardLegend legend = (StandardLegend) chart.getLegend();
    //      legend.setDisplaySeriesShapes(true);

    // get a reference to the plot for further customisation...
    final CategoryPlot plot = chart.getCategoryPlot();
    //    plot.getDomainAxis().setMaxCategoryLabelWidthRatio(10.0f);
    plot.setRangeAxis(new DateAxis("Date"));
    final CategoryToolTipGenerator toolTipGenerator = new StandardCategoryToolTipGenerator("",
            DateFormat.getDateInstance());
    //        final CategoryItemRenderer renderer = new LineAndShapeRenderer(LineAndShapeRenderer.SHAPES);
    //      renderer.setToolTipGenerator(toolTipGenerator);
    //    plot.setRenderer(renderer);

    // ****************************************************************************
    // * JFREECHART DEVELOPER GUIDE                                               *
    // * The JFreeChart Developer Guide, written by David Gilbert, is available   *
    // * to purchase from Object Refinery Limited:                                *
    // *                                                                          *
    // * http://www.object-refinery.com/jfreechart/guide.html                     *
    // *                                                                          *
    // * Sales are used to provide funding for the JFreeChart project - please    * 
    // * support us so that we can continue developing free software.             *
    // ****************************************************************************

    // OPTIONAL CUSTOMISATION COMPLETED.

    // add the chart to a panel...
    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    setContentPane(chartPanel);

}

From source file:com.att.aro.ui.view.overviewtab.FileTypesChartPanel.java

private JFreeChart initializeChart() {
    JFreeChart chart = ChartFactory.createBarChart(
            ResourceBundleHelper.getMessageString("chart.filetype.title"), null,
            ResourceBundleHelper.getMessageString("simple.percent"), null, PlotOrientation.HORIZONTAL, false,
            false, false);//from   ww  w  .j a  v  a2s .c om

    //chart.setBackgroundPaint(fileTypePanel.getBackground());
    chart.setBackgroundPaint(this.getBackground());
    chart.getTitle().setFont(AROUIManager.HEADER_FONT);

    this.cPlot = chart.getCategoryPlot();
    cPlot.setBackgroundPaint(Color.white);
    cPlot.setDomainGridlinePaint(Color.gray);
    cPlot.setRangeGridlinePaint(Color.gray);
    cPlot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_RIGHT);

    CategoryAxis domainAxis = cPlot.getDomainAxis();
    domainAxis.setMaximumCategoryLabelWidthRatio(.5f);
    domainAxis.setLabelFont(AROUIManager.LABEL_FONT);
    domainAxis.setTickLabelFont(AROUIManager.LABEL_FONT);

    NumberAxis rangeAxis = (NumberAxis) cPlot.getRangeAxis();
    rangeAxis.setRange(0.0, 100.0);
    rangeAxis.setTickUnit(new NumberTickUnit(10));
    rangeAxis.setLabelFont(AROUIManager.LABEL_FONT);
    rangeAxis.setTickLabelFont(AROUIManager.LABEL_FONT);

    BarRenderer renderer = new StackedBarRenderer();
    renderer.setBasePaint(AROUIManager.CHART_BAR_COLOR);
    renderer.setAutoPopulateSeriesPaint(false);
    renderer.setBaseItemLabelGenerator(new PercentLabelGenerator());
    renderer.setBaseItemLabelsVisible(true);
    renderer.setBaseItemLabelPaint(Color.black);

    // Make second bar in stack invisible
    renderer.setSeriesItemLabelsVisible(1, false);
    renderer.setSeriesPaint(1, new Color(0, 0, 0, 0));

    renderer.setBaseToolTipGenerator(new CategoryToolTipGenerator() {
        @Override
        public String generateToolTip(CategoryDataset dataset, int row, int column) {

            FileTypeSummary summary = fileTypeContent.get(column);

            return MessageFormat.format(ResourceBundleHelper.getMessageString("chart.filetype.tooltip"),
                    NumberFormat.getIntegerInstance().format(summary.getBytes()));
        }
    });

    ItemLabelPosition insideItemlabelposition = new ItemLabelPosition(ItemLabelAnchor.INSIDE3,
            TextAnchor.CENTER_RIGHT);
    renderer.setBasePositiveItemLabelPosition(insideItemlabelposition);

    ItemLabelPosition outsideItemlabelposition = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE3,
            TextAnchor.CENTER_LEFT);
    renderer.setPositiveItemLabelPositionFallback(outsideItemlabelposition);

    BarPainter painter = new StandardBarPainter();
    renderer.setBarPainter(painter);
    renderer.setShadowVisible(false);
    renderer.setMaximumBarWidth(0.1);

    cPlot.setRenderer(renderer);
    cPlot.getDomainAxis().setMaximumCategoryLabelLines(2);

    return chart;
}

From source file:biz.ixnay.pivot.charts.skin.jfree.BarChartViewSkin.java

@Override
protected JFreeChart createChart() {
    BarChartView chartView = (BarChartView) getComponent();

    String title = chartView.getTitle();
    String horizontalAxisLabel = chartView.getHorizontalAxisLabel();
    String verticalAxisLabel = chartView.getVerticalAxisLabel();
    boolean showLegend = chartView.getShowLegend();

    String seriesNameKey = chartView.getSeriesNameKey();
    List<?> chartData = chartView.getChartData();

    // TODO Make plot orientation a style property

    JFreeChart chart;/*from w w  w  .  java 2 s. c om*/
    ChartView.CategorySequence categories = chartView.getCategories();
    if (categories.getLength() > 0) {
        CategorySeriesDataset dataset = new CategorySeriesDataset(categories, seriesNameKey, chartData);

        if (stacked && threeDimensional) {
            chart = ChartFactory.createStackedBarChart3D(title, horizontalAxisLabel, verticalAxisLabel, dataset,
                    PlotOrientation.VERTICAL, showLegend, false, false);
        } else if (stacked) {
            chart = ChartFactory.createStackedBarChart(title, horizontalAxisLabel, verticalAxisLabel, dataset,
                    PlotOrientation.VERTICAL, showLegend, false, false);
        } else if (threeDimensional) {
            chart = ChartFactory.createBarChart3D(title, horizontalAxisLabel, verticalAxisLabel, dataset,
                    PlotOrientation.VERTICAL, showLegend, false, false);
        } else {
            chart = ChartFactory.createBarChart(title, horizontalAxisLabel, verticalAxisLabel, dataset,
                    PlotOrientation.VERTICAL, showLegend, false, false);
        }

        CategoryPlot plot = (CategoryPlot) chart.getPlot();
        CategoryAxis domainAxis = plot.getDomainAxis();
        CategoryLabelPositions categoryLabelPositions = CategoryLabelPositions
                .createUpRotationLabelPositions(categoryLabelRotation);
        domainAxis.setCategoryLabelPositions(categoryLabelPositions);
    } else {
        // TODO Make the dateAxis argument a style property
        chart = ChartFactory.createXYBarChart(title, horizontalAxisLabel, false, verticalAxisLabel,
                new IntervalSeriesDataset(seriesNameKey, chartData), PlotOrientation.VERTICAL, showLegend,
                false, false);
    }

    return chart;
}

From source file:com.xilinx.ultrascale.gui.DMABarChart.java

private void makeChart() {
    dataset = new DefaultCategoryDataset();
    chart = ChartFactory.createBarChart("", "Time Interval", "Throughput (Gbps)", dataset,
            PlotOrientation.VERTICAL, true, true, false);
    chart.setBackgroundPaint(bg);/*w w w  .  j  av a2  s .  c o  m*/
    TextTitle ttitle = new TextTitle(title, new Font(title, Font.BOLD, 15));
    ttitle.setPaint(Color.WHITE);
    chart.setTitle(ttitle);

    CategoryPlot plot = chart.getCategoryPlot();
    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);
    ValueAxis axis = plot.getRangeAxis();
    axis.setUpperBound(64.0);
    axis.setLowerBound(0.0);
    axis.setTickLabelPaint(new Color(185, 185, 185));
    axis.setLabelPaint(new Color(185, 185, 185));

    CategoryAxis caxis = plot.getDomainAxis();
    caxis.setTickLabelPaint(new Color(185, 185, 185));
    caxis.setLabelPaint(new Color(185, 185, 185));

    renderer.setItemMargin(0);
    renderer.setSeriesPaint(0, new Color(0x2e, 0x90, 0x18));//(0x17, 0x7b, 0x7c));
    renderer.setSeriesPaint(1, new Color(0x12, 0x45, 0x73));//(0xa2, 0x45, 0x73)
    renderer.setSeriesPaint(3, new Color(0xff, 0x80, 0x40));
    renderer.setSeriesPaint(2, new Color(0x6f, 0x2c, 0x85));
    renderer.setSeriesPaint(4, new Color(0xa1, 0x60, 0x98));
    renderer.setBaseToolTipGenerator(
            new StandardCategoryToolTipGenerator("{0}:{2}", new DecimalFormat("0.000")));
    //renderer.setMaximumBarWidth(0.05);
    //        addDummy();
}