Example usage for org.jfree.chart JFreeChart getCategoryPlot

List of usage examples for org.jfree.chart JFreeChart getCategoryPlot

Introduction

In this page you can find the example usage for org.jfree.chart JFreeChart getCategoryPlot.

Prototype

public CategoryPlot getCategoryPlot() 

Source Link

Document

Returns the plot cast as a CategoryPlot .

Usage

From source file:pt.ist.expenditureTrackingSystem.presentationTier.actions.statistics.ChartGenerator.java

protected static JFreeChart createBarChart(final CategoryDataset categoryDataset, final String title) {
    final JFreeChart chart = ChartFactory.createBarChart3D(title, "", "", categoryDataset,
            PlotOrientation.VERTICAL, true, true, false);
    chart.setBackgroundPaint(new Color(0xF5, 0xF5, 0xF5));

    final CategoryPlot plot = chart.getCategoryPlot();
    plot.setRangeAxisLocation(AxisLocation.TOP_OR_LEFT);

    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    return chart;
}

From source file:cl.apr.pdf.chart.BarChartAviso.java

public static BufferedImage crearBarchart(List<BarChartItem> barChartItems) {
    BufferedImage bi = null;/*from   w  w w .  j  a  va2  s .c  o  m*/
    try {

        ChartFactory.setChartTheme(StandardChartTheme.createJFreeTheme());
        //ChartFactory.setChartTheme(StandardChartTheme.createDarknessTheme());

        /* Step - 1: Define the data for the bar chart  */
        DefaultCategoryDataset my_bar_chart_dataset = new DefaultCategoryDataset();
        int i = 0;
        for (BarChartItem barChartItem : barChartItems) {
            if (barChartItem.getNombre().equals("-")) {
                my_bar_chart_dataset.addValue(barChartItem.getValor(), "serie", (++i) + "");
            } else
                my_bar_chart_dataset.addValue(barChartItem.getValor(), "serie", barChartItem.getNombre());
        }
        //                my_bar_chart_dataset.addValue(34, "mes", "Ene");
        //                my_bar_chart_dataset.addValue(25, "mes", "Feb");
        //                my_bar_chart_dataset.addValue(22, "mes", "Mar");
        //                my_bar_chart_dataset.addValue(12, "mes", "Abr");
        //                my_bar_chart_dataset.addValue(40, "mes", "May");
        //                my_bar_chart_dataset.addValue(30, "mes", "jun");
        //                my_bar_chart_dataset.addValue(2, "mes", "Jul");
        //                my_bar_chart_dataset.addValue(15, "mes", "Ago");

        /* Step -2:Define the JFreeChart object to create bar chart */
        //JFreeChart chart=ChartFactory.createBarChart("Detalle de sus consumos","","MT3",my_bar_chart_dataset,PlotOrientation.VERTICAL,true,true,false);    
        JFreeChart chart = ChartFactory.createBarChart("", "", "MT3", my_bar_chart_dataset,
                PlotOrientation.VERTICAL, true, true, false);

        //chart.setBackgroundPaint(Color.lightGray);
        // get a reference to the plot for further customisation... 
        final CategoryPlot plot = chart.getCategoryPlot();
        CategoryItemRenderer renderer = new CustomRenderer();

        renderer.setSeriesPaint(0, Color.DARK_GRAY);

        plot.setRenderer(renderer);
        plot.setBackgroundPaint(Color.white);

        chart.setBorderVisible(false);
        chart.setBackgroundPaint(Color.white);
        chart.setBorderStroke(null);
        chart.getLegend().visible = false;
        /* Step -3: Write the output as PNG file with bar chart information */
        int width = 480; /* Width of the image */
        int height = 250; /* Height of the image */
        bi = chart.createBufferedImage(width, height);

        /*
                
        File BarChart=new File("output_chart.png");              
        ChartUtilities.saveChartAsPNG(BarChart,BarChartObject,width,height); 
                */
    } catch (Exception i) {
        System.out.println(i);
    }

    return bi;
}

From source file:com.compomics.pepshell.view.statistics.JFreeChartPanel.java

static void prettifyChart(JFreeChart chart) {
    // set title font
    chart.getTitle().setFont(new Font("Tahoma", Font.BOLD, 12));
    if (chart.getPlot() instanceof XYPlot) {
        XYPlot xYPlot = chart.getXYPlot();
        setupPlot(xYPlot);/*from   www  .  jav a 2 s. c  om*/
    } else if (chart.getPlot() instanceof CategoryPlot) {
        CategoryPlot categoryPlot = chart.getCategoryPlot();
        setupPlot(categoryPlot);
    }
    setShadowVisible(chart, false);
}

From source file:com.hmsinc.epicenter.webapp.chart.ChartService.java

/**
 * @param chart//from  w w  w  .ja  v  a2  s .c  o  m
 */
private static void configureRenderer(final JFreeChart chart, final AbstractChart adapter) {

    if (ChartType.BAR.equals(adapter.getType())) {

        chart.getCategoryPlot().setRenderer(getBarRenderer(adapter));

    } else if (ChartType.TIMESERIES_BAR.equals(adapter.getType())) {

        chart.getXYPlot().setRenderer(getTimeSeriesBarRenderer(adapter));

    } else if (ChartType.MOUNTAIN.equals(adapter.getType())) {

        chart.getXYPlot().setRenderer(getMountainRenderer(adapter));
        chart.getXYPlot().setSeriesRenderingOrder(SeriesRenderingOrder.FORWARD);

    } else {

        final XYItemRenderer renderer = chart.getXYPlot().getRenderer();

        for (int i = 0; i < adapter.getColors().size(); i++) {

            final Color c = adapter.getColors().get(i);
            renderer.setSeriesPaint(i, c);
            renderer.setSeriesOutlinePaint(i, c.brighter());
        }

        for (int i = 0; i < adapter.getStrokes().size(); i++) {
            renderer.setSeriesStroke(i, adapter.getStrokes().get(i));
        }

        if (renderer instanceof XYLineAndShapeRenderer) {
            ((XYLineAndShapeRenderer) renderer).setDrawSeriesLineAsPath(true);
        }

    }

}

From source file:spec.reporter.Utils.java

public static void createBmResultGraph(BenchmarkRecord record) {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    String iterName = "";
    double max = 0;
    double min = Long.MAX_VALUE;
    for (int i = 0; i < record.iterRecords.size(); i++) {
        BenchmarkRecord.IterationRecord iterRecord = (BenchmarkRecord.IterationRecord) record.iterRecords
                .get(i);//w ww . ja  v a 2  s .c  om
        String shortName = iterRecord.iterName.replaceFirst("ation", "");
        if (iterRecord.score > max) {
            max = iterRecord.score;
            iterName = shortName;
        }

        if (iterRecord.score < min) {
            min = iterRecord.score;
        }

        dataset.addValue(iterRecord.score, " ", shortName);
    }

    JFreeChart chart = ChartFactory.createLineChart("  ", "iterations", Constants.WORKLOAD_METRIC, dataset,
            PlotOrientation.VERTICAL, false, true, false);
    CategoryPlot plot = chart.getCategoryPlot();
    plot.setBackgroundPaint(new Color(201, 222, 254));
    plot.setRangeGridlinePaint(Color.WHITE);
    if (record.isValidRun() && min != Long.MAX_VALUE) {
        plot.getRangeAxis().setRange(min - 10, max + 10);
    } else {
        plot.getRangeAxis().setRange(0, max + 10);
    }
    ValueMarker vm = new ValueMarker(record.maxScore);
    vm.setLabel(Utils.df.format(record.maxScore));
    vm.setLabelAnchor(RectangleAnchor.TOP_LEFT);
    vm.setLabelTextAnchor(TextAnchor.HALF_ASCENT_LEFT);

    plot.addRangeMarker(vm);
    CategoryMarker marker = new CategoryMarker(iterName);
    marker.setDrawAsLine(true);
    marker.setPaint(vm.getPaint());
    plot.addDomainMarker(marker);
    LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
    renderer.setShapesVisible(true);
    renderer.setDrawOutlines(true);
    renderer.setUseFillPaint(true);
    renderer.setFillPaint(Color.WHITE);
    renderer.setSeriesPaint(0, Color.BLUE.darker());

    try {
        ChartUtilities.saveChartAsJPEG(new File(Utils.getFullImageName(record.name + "_results")), chart, 300,
                200);
    } catch (Exception e) {
        System.out.println("Problems...");
    }
}

From source file:org.opennms.web.charts.ChartUtils.java

/**
 * @param barChart TODO//from  w  ww.j a v  a  2 s  .  co  m
 * @param subLabelClass
 */
private static void addSubLabels(JFreeChart barChart, String subLabelClass) {
    ExtendedCategoryAxis subLabels;
    CategoryPlot plot = barChart.getCategoryPlot();
    try {
        subLabels = (ExtendedCategoryAxis) Class.forName(subLabelClass).newInstance();
        List<?> cats = plot.getCategories();
        for (int i = 0; i < cats.size(); i++) {
            subLabels.addSubLabel((Comparable<?>) cats.get(i), cats.get(i).toString());
        }
        plot.setDomainAxis(subLabels);
    } catch (InstantiationException e) {
        LOG.error("getBarChart: Couldn't instantiate configured CategorySubLabels class: {}", subLabelClass, e);
    } catch (IllegalAccessException e) {
        LOG.error("getBarChart: Couldn't instantiate configured CategorySubLabels class: {}", subLabelClass, e);
    } catch (ClassNotFoundException e) {
        LOG.error("getBarChart: Couldn't instantiate configured CategorySubLabels class: {}", subLabelClass, e);
    }
}

From source file:org.nbheaven.sqe.codedefects.dashboard.controlcenter.panels.Statistics.java

private static JFreeChart createOverviewPanel(DefaultCategoryDataset dataSet) {

    JFreeChart overview = org.jfree.chart.ChartFactory.createStackedBarChart(null, null, "CodeDefects", dataSet,
            PlotOrientation.HORIZONTAL, false, true, false);
    overview.setBorderVisible(false);//from  w  ww.  ja v a  2 s  . co m
    overview.setBackgroundPaint(Color.WHITE);
    overview.setAntiAlias(true);
    overview.setNotify(true);

    CategoryPlot overviewPlot = overview.getCategoryPlot();
    overviewPlot.setRangeGridlinePaint(Color.BLACK);
    overviewPlot.setDomainGridlinePaint(Color.BLACK);
    overviewPlot.setBackgroundPaint(Color.WHITE);
    overviewPlot.setForegroundAlpha(0.7f);
    overviewPlot.setRangeAxisLocation(AxisLocation.getOpposite(overviewPlot.getRangeAxisLocation()));

    CategoryAxis domainAxis = overviewPlot.getDomainAxis();
    domainAxis.setVisible(true);

    LogarithmicAxis rangeAxis = new LogarithmicAxis("CodeDefects");
    rangeAxis.setLabel(null);
    rangeAxis.setStrictValuesFlag(false);
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    overviewPlot.setRangeAxis(rangeAxis);

    CategoryItemRenderer categoryItemRenderer = new StackedBarRenderer(); //3D();
    //        categoryItemRenderers[0].setPaint(Color.RED);
    categoryItemRenderer.setSeriesPaint(0, Color.RED);
    categoryItemRenderer.setSeriesPaint(1, Color.ORANGE);
    categoryItemRenderer.setSeriesPaint(2, Color.YELLOW);

    categoryItemRenderer.setBaseItemLabelsVisible(true);

    overviewPlot.setRenderer(categoryItemRenderer);

    return overview;
}

From source file:org.opennms.netmgt.charts.ChartUtils.java

/**
 * @param barChart TODO//w  w w  .  j a va2s  .  c  o  m
 * @param subLabelClass
 */
private static void addSubLabels(JFreeChart barChart, String subLabelClass) {
    ExtendedCategoryAxis subLabels;
    CategoryPlot plot = barChart.getCategoryPlot();
    try {
        subLabels = (ExtendedCategoryAxis) Class.forName(subLabelClass).newInstance();
        List<?> cats = plot.getCategories();
        for (int i = 0; i < cats.size(); i++) {
            subLabels.addSubLabel((Comparable<?>) cats.get(i), cats.get(i).toString());
        }
        plot.setDomainAxis(subLabels);
    } catch (InstantiationException e) {
        log().error("getBarChart: Couldn't instantiate configured CategorySubLabels class: " + subLabelClass,
                e);
    } catch (IllegalAccessException e) {
        log().error("getBarChart: Couldn't instantiate configured CategorySubLabels class: " + subLabelClass,
                e);
    } catch (ClassNotFoundException e) {
        log().error("getBarChart: Couldn't instantiate configured CategorySubLabels class: " + subLabelClass,
                e);
    }
}

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

/**
 * Creates the chart with the data from the given data set.
 * //w w w .j  a v  a2  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.wpi.cs.wpisuitetng.modules.requirementmanager.view.requirements.NewBarChartPanel.java

/**
 * @param dataset the data to be shown by the chart
 * @param title the title of the chart(either status or iteration) @return
 *            the created bar graph/*  w w w. j  av  a  2  s . c  o  m*/
 */
private static JFreeChart createChart(CategoryDataset dataset, String title) {
    JFreeChart chart = ChartFactory.createBarChart(title, // chart title
            "Name", // domain axis label
            "Value", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, false);

    chart.setBackgroundPaint(Color.white);
    CategoryPlot plot = chart.getCategoryPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setDomainGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.white);

    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    return chart;
}