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:de.fub.maps.project.detector.model.inference.ui.charts.PrecisionRecallBarChartPanel.java

/**
 * Creates new form PrecisionRecallBarChartPanel
 *///from   www. ja  va2s.  c  o m
public PrecisionRecallBarChartPanel() {
    super();
    initComponents();
    barChart = ChartFactory.createBarChart(
            NbBundle.getMessage(PrecisionRecallBarChartPanel.class, "CLT_Chart_Precision_Recall_Name"),
            NbBundle.getMessage(PrecisionRecallBarChartPanel.class, "CLT_Doman_Axis_Name"),
            NbBundle.getMessage(PrecisionRecallBarChartPanel.class, "CLT_Value_Axis_Name"), dataset,
            PlotOrientation.VERTICAL, true, true, true);

    Font font = new JLabel().getFont().deriveFont(Font.BOLD, 14);

    barChart.getTitle().setFont(font);
    barChart.getTitle().setPaint(new Color(153, 153, 153));

    plot = barChart.getCategoryPlot();
    NumberAxis preciAxis = new NumberAxis(
            NbBundle.getMessage(PrecisionRecallBarChartPanel.class, "CLT_Value_Axis_Name"));
    preciAxis.setAutoRange(true);
    preciAxis.setUpperMargin(.20);
    plot.setRangeAxis(0, preciAxis);
    plot.setRangeAxisLocation(0, AxisLocation.TOP_OR_LEFT);
    plot.setBackgroundPaint(Color.white);

    BarRenderer barRenderer = new BarRenderer();
    barRenderer.setBarPainter(new StandardBarPainter());
    barRenderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
    barRenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator(
            StandardCategoryItemLabelGenerator.DEFAULT_LABEL_FORMAT_STRING, new CustomNumberFormat()));
    barRenderer.setBaseItemLabelsVisible(true);
    barRenderer.setSeriesPaint(0, precColor);
    barRenderer.setSeriesPaint(1, recColor);

    plot.setRenderer(barRenderer);

    chartPanel = new ChartPanel(barChart, false);
    chartPanel.setVerticalAxisTrace(false);
    add(chartPanel, BorderLayout.CENTER);
}

From source file:loansystem.visual.panel.StartPage.java

private void graficoPrestamoXMes() {
    ArrayList<GraficoEntidad> graficos;
    graficos = gDao.obtenerPrestamosPorMes();

    if (graficos.size() > 0) {
        DefaultCategoryDataset datos = new DefaultCategoryDataset();

        for (GraficoEntidad result : graficos) {
            datos.addValue(result.getValor(), result.getSerie(), result.getValorEje());
        }/*from   w  ww.  j  av a  2  s  .c om*/

        JFreeChart grafica = ChartFactory.createBarChart("Registros Por Mes", "Mes", "Prstamos", datos,
                PlotOrientation.VERTICAL, true, true, false);
        ChartPanel panel = new ChartPanel(grafica);
        pnelPrestamosMes.add(panel);
        pnelPrestamosMes.revalidate();
        pnelPrestamosMes.repaint();

    }

}

From source file:user.CreateChart.java

private ImageIcon barChart(CategoryDataset dataset, String name, String X, String Y) {

    final JFreeChart chart = ChartFactory.createBarChart(name, // chart title
            X, // domain axis label
            Y, // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips?
            false // URLs?
    );/*from   w  w  w .  j  a va 2s  .  c  o  m*/
    final CategoryPlot plot = chart.getCategoryPlot();
    final org.jfree.chart.axis.NumberAxis rangeAxis = (org.jfree.chart.axis.NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(org.jfree.chart.axis.NumberAxis.createIntegerTickUnits());

    ImageIcon ii = new ImageIcon(chart.createBufferedImage(592, 500));
    return ii;
}

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

@Override
public void setGraphData(PepshellProtein aPepshellProtein) {
    if (aPepshellProtein != null && referenceExperiment.getProteins().contains(aPepshellProtein)
            && experimentToCompareTo.getProteins().contains(aPepshellProtein)) {
        CategoryDataset dataset = createRatioDataset(aPepshellProtein);
        JFreeChart ratioChart = ChartFactory.createBarChart("log ratios of peptides on a protein",
                aPepshellProtein.getVisibleAccession(), "log^2 ratio", dataset, PlotOrientation.VERTICAL, true,
                true, false);/*from w ww . j av a2 s  .co m*/
        prettifyChart(ratioChart);
        chart.setChart(ratioChart);
    }

}

From source file:org.jboss.weld.benchmark.charts.Chart.java

/**
 * Saving a chart to hard disk as png image
 *
 * @param path absolute path//from   ww  w . j  a  v a  2s . c o m
 * @return true if no errors occurred
 */
public Boolean saveImageTo(String path) {
    try {
        JFreeChart lineChartObject = ChartFactory.createBarChart(NAME, X_AXIS_NAME, Y_AXIS_NAME,
                lineChartDataset, PlotOrientation.VERTICAL, true, true, false);

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

        plot.setDomainAxis(new CategoryAxis() {
            private static final long serialVersionUID = 1L;

            @Override
            protected TextBlock createLabel(@SuppressWarnings("rawtypes") Comparable category, float width,
                    RectangleEdge edge, Graphics2D g2) {
                TextBlock label = TextUtilities.createTextBlock(category.toString(), getTickLabelFont(category),
                        getTickLabelPaint(category), ONE_PART_WIDTH - 30, 2, new G2TextMeasurer(g2));

                label.setLineAlignment(HorizontalAlignment.LEFT);
                return label;
            }
        });

        File lineChart = new File(path, NAME + ".png");
        ChartUtilities.saveChartAsPNG(lineChart, lineChartObject,
                ONE_PART_WIDTH * lineChartDataset.getColumnCount(), GRAPH_HEIGHT);
    } catch (IOException e) {
        e.printStackTrace();
        return false;
    }
    return true;
}

From source file:edu.jhuapl.graphs.jfreechart.JFreeChartBarGraphSource.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);
    Double maxBarWidth = getParam(MAX_BAR_WIDTH, Double.class, DEFAULT_MAX_BAR_WIDTH);
    JFreeChart result = ChartFactory.createBarChart(title, xLabel, yLabel, dataset, orientation, legend,
            graphToolTip, false);/*from www  .  j av  a  2 s . com*/
    CategoryBarGraphRenderer renderer = new CategoryBarGraphRenderer(data);

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

    return result;
}

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

@Override
public void setGraphData(PepshellProtein aPepshellProtein) {
    //obligatory checks
    if (aPepshellProtein != null) {
        if (aPepshellProtein != currentPepshellProtein) {
            //TODO: run this outside of the gui thread
            CategoryDataset dataset = createRatioDataset(aPepshellProtein);
            JFreeChart ratioChart = ChartFactory.createBarChart("log 2 ratios of peptides on a protein",
                    aPepshellProtein.getVisibleAccession(), "log 2 ratio", dataset, PlotOrientation.VERTICAL,
                    true, true, false);/*from  w w w. j av  a2 s  . c  o m*/
            prettifyChart(ratioChart);
            //((CategoryPlot)ratioChart.getPlot()).setRenderer(new StatisticalBarRenderer());
            chart.setChart(ratioChart);
        }
    } else {
        chart.setChart(null);
        this.getGraphics().drawString("missing data", 0, 0);
    }
}

From source file:org.gaixie.micrite.crm.action.CustomerChartAction.java

/**
 * 2D/* w w w.j a  v a2  s  . c om*/
 * @return "success"
 */
public String getBarChart() {
    CategoryDataset dca = customerService.getCustomerSourceBarDataset(this.getQueryBean());
    chart = ChartFactory.createBarChart(getText("customer.source.chart.bar.title"),
            getText("customer.source.chart.bar.y"), getText("customer.source.chart.bar.x"), dca,
            PlotOrientation.VERTICAL, true, false, false);
    BarStyle.styleOne(chart);
    this.putChartResultList(chart);
    return SUCCESS;
}

From source file:com.wattzap.view.graphs.DistributionGraph.java

public DistributionGraph(ArrayList<Telemetry> telemetry[], DistributionAccessor da, String domainLabel,
        int scale) {
    super();//w w w  . j  av  a 2s. co m

    this.telemetry = telemetry;
    this.da = da;

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

    chart.setBackgroundPaint(Color.white);

    // get a reference to the plot for further customisation...
    plot = (CategoryPlot) chart.getPlot();

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

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

    // set up gradient paints for series...
    GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.gray, 0.0f, 0.0f, new Color(0, 0, 64));
    renderer.setSeriesPaint(0, gp0);

    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0));
    // OPTIONAL CUSTOMISATION COMPLETED.

    chartPanel = new ChartPanel(chart);
    chartPanel.setSize(100, 800);
    chartPanel.setFillZoomRectangle(true);
    chartPanel.setMouseWheelEnabled(true);
    setLayout(new BorderLayout());
    add(chartPanel, BorderLayout.CENTER);

    BucketPanel bucketPanel = new BucketPanel(this, scale);
    add(bucketPanel, BorderLayout.SOUTH);

    setBackground(Color.black);
    chartPanel.revalidate();
    setVisible(true);
}

From source file:com.jimaginary.machine.graph.params.BernoulliParamPropertyPanel.java

private void initChart() {
    // BAR CHART// w  ww. ja v a 2 s.  c o  m
    DefaultCategoryDataset chartData = new DefaultCategoryDataset();
    if (idxNames != null) {
        chartData.setValue(mathFunc.getParameter(PARAM_PROB), mathFunc.getParamName(0), idxNames[0]);
        chartData.setValue(1.f - mathFunc.getParameter(PARAM_PROB), mathFunc.getParamName(0), idxNames[1]);
    } else {
        chartData.setValue(mathFunc.getParameter(PARAM_PROB), mathFunc.getParamName(0), "0");
        chartData.setValue(1.f - mathFunc.getParameter(PARAM_PROB), mathFunc.getParamName(0), "1");
    }
    JFreeChart chart = ChartFactory.createBarChart("Bernoulli Distribution (PMF)",
            mathFunc.getParamName(PARAM_PROB), "probability", chartData, //Chart Data 
            PlotOrientation.VERTICAL, // orientation
            true, // include legend?
            true, // include tooltips?
            false // include URLs?
    );

    if (chartPanel != null) {
        jPanelChart.remove(chartPanel);
    }
    chartPanel = new ChartPanel(chart);
    jPanelChart.setLayout(new java.awt.BorderLayout());
    jPanelChart.add(chartPanel, BorderLayout.CENTER);
    jPanelChart.validate();
}