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:org.owasp.jbrofuzz.graph.canvas.ResponseSizeChart.java

public ChartPanel getPlotCanvas() {

    final JFreeChart chart = ChartFactory.createBarChart("JBroFuzz Response Size Bar Chart", // chart title
            "File Name", // domain axis label
            "Response Size (bytes)", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            false, // include legend
            true, // tooltips?
            true // URLs?
    );/*from  w  w w.j  av a 2s.  c  o m*/

    final Plot plot = chart.getPlot();
    plot.setBackgroundImage(ImageCreator.IMG_OWASP_MED.getImage());
    plot.setBackgroundImageAlignment(Align.TOP_RIGHT);

    final CategoryItemRenderer renderer = chart.getCategoryPlot().getRenderer();
    renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());

    return new ChartPanel(chart);

}

From source file:playground.thibautd.utils.charts.ChartsAxisUnifier.java

public void addChart(final JFreeChart chart) {
    charts.add(chart);//from  w w  w.  jav a  2 s.  c om

    if (unifyX) {
        Plot plot = chart.getPlot();
        if (plot instanceof XYPlot) {
            ValueAxis axis = chart.getXYPlot().getDomainAxis();

            Range range = axis.getRange();
            lowerX = Math.min(lowerX, range.getLowerBound());
            upperX = Math.max(upperX, range.getUpperBound());
        }
    }

    if (unifyY) {
        Plot plot = chart.getPlot();
        ValueAxis axis;
        if (plot instanceof XYPlot) {
            axis = chart.getXYPlot().getRangeAxis();
        } else if (plot instanceof CategoryPlot) {
            axis = chart.getCategoryPlot().getRangeAxis();
        } else {
            return;
        }

        Range range = axis.getRange();
        lowerY = Math.min(lowerY, range.getLowerBound());
        upperY = Math.max(upperY, range.getUpperBound());
    }
}

From source file:TelasBanzos.TelaRelatorioDiadaSemana.java

/**
 * Creates new form TelaNovoOrcamento// w ww  . j av  a  2  s . c om
 */
public TelaRelatorioDiadaSemana() {
    initComponents();

    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    dataset.setValue(2, "3", "Domingo");
    dataset.setValue(5, "3", "Segunda");
    dataset.setValue(4, "3", "Tera");
    dataset.setValue(7, "3", "Quarta");
    dataset.setValue(6, "3", "Quinta");
    dataset.setValue(2, "3", "Sexta");
    dataset.setValue(4, "3", "Sbado");

    JFreeChart chart = ChartFactory.createBarChart("Alunos matriculados por dia da semana", "Dia da semana",
            "Quantidade Alunos", dataset, PlotOrientation.VERTICAL, false, true, false);
    ChartPanel myChartPanel = new ChartPanel(chart, true);
    pnGraf.add(myChartPanel);

    //colocar cor nas barras
    CategoryPlot plot = chart.getCategoryPlot();
    BarRenderer render = (BarRenderer) plot.getRenderer();
    render.setSeriesPaint(0, Color.ORANGE);

    setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("BanzosIcon.png")));//para setar um icone na janela
}

From source file:edu.ucla.stat.SOCR.chart.demo.BarChartDemo4.java

/**
 * Creates a sample chart.//  ww w. j a  v  a2s . c  o  m
 * 
 * @param dataset  the dataset.
 * 
 * @return The chart.
 */
protected JFreeChart createChart(CategoryDataset dataset) {

    // create the chart...
    JFreeChart chart = ChartFactory.createBarChart(chartTitle, // chart title
            domainLabel, // domain axis label
            rangeLabel, // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, !legendPanelOn, // 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(0xBBBBDD));

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

    // 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);
    renderer.setMaximumBarWidth(0.10);

    // set up gradient paints for series...
    GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, Color.lightGray);
    GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, Color.lightGray);
    renderer.setSeriesPaint(0, gp0);
    renderer.setSeriesPaint(1, gp1);

    // OPTIONAL CUSTOMISATION COMPLETED.
    renderer.setLegendItemLabelGenerator(new SOCRCategorySeriesLabelGenerator());
    setCategorySummary(dataset);
    return chart;

}

From source file:hudson.plugins.codeviation.RepositoryView.java

private JFreeChart createChart(CategoryDataset dataset, int max) {

    final JFreeChart chart = ChartFactory.createLineChart(null, // chart title
            null, // unused
            "counts", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips
            false // urls
    );/*from w w  w . j  av a  2 s  . c o m*/

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

    final LegendTitle legend = chart.getLegend();
    legend.setPosition(RectangleEdge.RIGHT);

    chart.setBackgroundPaint(Color.white);

    final CategoryPlot plot = chart.getCategoryPlot();

    // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
    plot.setBackgroundPaint(Color.WHITE);
    plot.setOutlinePaint(null);
    plot.setRangeGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.black);

    CategoryAxis domainAxis = new ShiftedCategoryAxis(null);
    plot.setDomainAxis(domainAxis);
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);
    domainAxis.setLowerMargin(0.0);
    domainAxis.setUpperMargin(0.0);
    domainAxis.setCategoryMargin(0.0);

    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setUpperBound(max * 1.2);
    rangeAxis.setLowerBound(0);

    final LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
    renderer.setStroke(new BasicStroke(4.0f));

    // crop extra space around the graph
    plot.setInsets(new RectangleInsets(5.0, 0, 0, 5.0));

    return chart;
}

From source file:userinterface.StateNetworkAdminRole.StateReportsJPanel.java

private JFreeChart createDonorsReportsChart(CategoryDataset dataset) {
    JFreeChart barChart = ChartFactory.createBarChart("No Of Registered Donors", "Year", "Registered Donors",
            dataset, PlotOrientation.VERTICAL, true, true, false);
    barChart.setBackgroundPaint(Color.white);
    // Set the background color of the chart
    barChart.getTitle().setPaint(Color.DARK_GRAY);
    barChart.setBorderVisible(true);/* w  ww.  ja v a2s. c om*/
    // Adjust the color of the title
    CategoryPlot plot = barChart.getCategoryPlot();
    plot.getRangeAxis().setLowerBound(0.0);
    // Get the Plot object for a bar graph
    plot.setBackgroundPaint(Color.white);
    plot.setRangeGridlinePaint(Color.blue);
    CategoryItemRenderer renderer = plot.getRenderer();
    renderer.setSeriesPaint(0, Color.decode("#00008B"));
    //return chart;
    return barChart;
}

From source file:com.kiyoshi.gui.AreaChart.java

private JFreeChart createChart(final CategoryDataset dataset) {

    final JFreeChart chart = ChartFactory.createAreaChart("Area Chart", // chart title
            "Category", // domain axis label
            "Value", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips
            false // urls
    );/*from w  w  w.  j a  va 2 s .  c o m*/

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    // set the background color for the chart...
    //        final StandardLegend legend = (StandardLegend) chart.getLegend();
    //      legend.setAnchor(StandardLegend.SOUTH);
    chart.setBackgroundPaint(Color.white);
    final CategoryPlot plot = chart.getCategoryPlot();
    plot.setForegroundAlpha(0.5f);

    //      plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinesVisible(true);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.white);

    final CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
    domainAxis.setLowerMargin(0.0);
    domainAxis.setUpperMargin(0.0);
    domainAxis.addCategoryLabelToolTip("Type 1", "The first type.");
    domainAxis.addCategoryLabelToolTip("Type 2", "The second type.");
    domainAxis.addCategoryLabelToolTip("Type 3", "The third type.");

    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setLabelAngle(0 * Math.PI / 2.0);
    // OPTIONAL CUSTOMISATION COMPLETED.

    return chart;

}

From source file:UserInterface.FinanceRole.DonateToPoorPeopleJPanel.java

private void populateTransactionTable(Person objPerson) {

    //Chart/*from   w  ww. j  a v  a 2s.  c  o m*/
    DefaultCategoryDataset dataSet = new DefaultCategoryDataset();

    //Table
    DefaultTableModel dtm = (DefaultTableModel) donationHistoryJTable.getModel();
    dtm.setRowCount(0);

    if (objPerson != null) {
        for (Transaction objTransaction : objPerson.getObjPoorPeopleTransactionDirectory()
                .getTransactionList()) {

            if (objTransaction.getTransactionSource()
                    .equals(Transaction.TransactionSourceType.FromWorldEnterprise.getValue())) {

                Object row[] = new Object[3];
                row[0] = objTransaction;
                row[1] = "$ " + objTransaction.getTransactionBDAmount();
                row[2] = objTransaction.getTransactionDateToDisplay();

                dtm.addRow(row);

                dataSet.setValue(objTransaction.getTransactionBDAmount(), "Amount",
                        objTransaction.getTransactionDateToDisplay());
            }
        }

        JFreeChart chart = ChartFactory.createBarChart3D("Overview of entire Transaction", "Transaction Date",
                "Amount in USD $", dataSet, PlotOrientation.VERTICAL, false, true, false);

        CategoryPlot plot = chart.getCategoryPlot();
        plot.setRangeGridlinePaint(Color.black);

        ChartPanel myChart = new ChartPanel(chart);
        transferDetailsJPanel.setLayout(new java.awt.BorderLayout());
        transferDetailsJPanel.add(myChart, BorderLayout.CENTER);
        transferDetailsJPanel.validate();

        transferDetailsJPanel.setVisible(true);
    } else {

        transferDetailsJPanel.setVisible(false);

    }
}

From source file:userinterface.HealthAnalystRole.ViewReportJPanel.java

private void createChart() {
    DefaultCategoryDataset healthDataset = new DefaultCategoryDataset();
    int selectedRow = tblHealthTable.getSelectedRow();
    Device effects = (Device) tblHealthTable.getValueAt(selectedRow, 0);
    //Device device= device.getEffectsOnBodyList().getEffectsOnBodyList().;

    for (Device d : organization.getDeviceDirectory().getDeviceList()) {
        if (d.getEffectsOnBodyList().getEffectsOnBodyList().isEmpty()
                || d.getEffectsOnBodyList().getEffectsOnBodyList().size() == 1) {
            JOptionPane.showMessageDialog(this,
                    "No body organs or only one body organ affected found. At least 2 organs effected records needed to show chart!",
                    "Warning", JOptionPane.INFORMATION_MESSAGE);
            return;
        } else {//from w  ww.j a  va 2 s .  com
            Double organ = Double.parseDouble(txtOrgan.getText());
            Double value = d.getMaxSAR();
        }
    }
    //ArrayList<EffectsOnBody> effectsOnBodyList = device.getEffectsOnBodyList().getEffectsOnBodyList();

    /*if (effectsOnBodyList.isEmpty() || effectsOnBodyList.size() == 1) {
    JOptionPane.showMessageDialog(this, "No body organs or only one body organ affected found. At least 2 organs effected records needed to show chart!", "Warning", JOptionPane.INFORMATION_MESSAGE);
    return;
    }*/
    Double organ = Double.parseDouble(txtOrgan.getText());
    for (Device device : organization.getDeviceDirectory().getDeviceList()) {
        for (EffectsOnBody b1 : device.getEffectsOnBodyList().getEffectsOnBodyList()) {
            Double value = device.getMaxSAR();

            //healthDataset.addValue(vitalSign.getHeartRate(),"Most Likely Diseases", device.getMaxSAR());
            //vitalSignDataset.addValue(vitalSign.getBloodPressure(),"BP", vitalSign.getTimestamp());
            //vitalSignDataset.addValue(vitalSign.getWeight(),"WT", vitalSign.getTimestamp());
        }

    }

    JFreeChart healthSignChart = ChartFactory.createBarChart3D("Effects On Health Chart", "Time Stamp", "Rate",
            healthDataset, PlotOrientation.VERTICAL, true, false, false);
    healthSignChart.setBackgroundPaint(Color.white);
    CategoryPlot vitalSignChartPlot = healthSignChart.getCategoryPlot();
    vitalSignChartPlot.setBackgroundPaint(Color.lightGray);

    CategoryAxis vitalSignDomainAxis = vitalSignChartPlot.getDomainAxis();
    vitalSignDomainAxis
            .setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0));

    NumberAxis vitalSignRangeAxis = (NumberAxis) vitalSignChartPlot.getRangeAxis();
    vitalSignRangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    ChartFrame chartFrame = new ChartFrame("Chart", healthSignChart);
    chartFrame.setVisible(true);
    chartFrame.setSize(500, 500);

}

From source file:j2se.jfreechart.barchart.BarChartDemo8.java

/**
 * Creates a sample chart.//from   w w  w.  jav a2 s . co m
 * 
 * @param dataset  the dataset.
 * 
 * @return The chart.
 */
private JFreeChart createChart(final CategoryDataset dataset) {

    // create the chart...
    final JFreeChart chart = ChartFactory.createBarChart("Bar Chart Demo 8", // chart title
            "Category", // domain axis label
            "Value", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            false, // include legend
            true, // tooltips?
            false // URLs?
    );

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

    // 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.white);
    plot.setRangeGridlinePaint(Color.white);

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

    // disable bar outlines...
    final CategoryItemRenderer renderer = plot.getRenderer();
    renderer.setSeriesItemLabelsVisible(0, Boolean.TRUE);

    final CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);

    // OPTIONAL CUSTOMISATION COMPLETED.

    return chart;

}