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:reports.util.BarChart2Scriptlet.java

/**
 *
 *///  w  w  w  .j ava2 s .c  o m
public void afterReportInit() throws JRScriptletException {

    JFreeChart jfreechart = ChartFactory.createBarChart("Bar Chart Demo", // chart title
            "States", // X Label
            "Sell Amount", // Y Label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips?
            false // URLs?
    );

    jfreechart.setBackgroundPaint(Color.white);
    CategoryPlot categoryplot = jfreechart.getCategoryPlot();
    categoryplot.setBackgroundPaint(Color.lightGray);
    categoryplot.setDomainGridlinePaint(Color.white);
    categoryplot.setRangeGridlinePaint(Color.white);

    LegendTitle legendtitle = (LegendTitle) jfreechart.getSubtitle(0);
    legendtitle.setPosition(RectangleEdge.RIGHT);
    legendtitle.setMargin(new RectangleInsets(UnitType.ABSOLUTE, 0.0D, 4D, 0.0D, 4D));

    IntervalMarker intervalmarker = new IntervalMarker(200D, 250D);
    intervalmarker.setLabel("Target Range");
    intervalmarker.setLabelFont(new Font("SansSerif", 2, 11));
    intervalmarker.setLabelAnchor(RectangleAnchor.LEFT);
    intervalmarker.setLabelTextAnchor(TextAnchor.CENTER_LEFT);
    intervalmarker.setPaint(new Color(222, 222, 255, 128));
    categoryplot.addRangeMarker(intervalmarker, Layer.BACKGROUND);

    NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    BarRenderer barrenderer = (BarRenderer) categoryplot.getRenderer();
    barrenderer.setDrawBarOutline(false);
    barrenderer.setItemMargin(0.10000000000000001D);

    GradientPaint gradientpaint = new GradientPaint(0.0F, 0.0F, Color.blue, 0.0F, 0.0F, new Color(0, 0, 64));
    GradientPaint gradientpaint1 = new GradientPaint(0.0F, 0.0F, Color.green, 0.0F, 0.0F, new Color(0, 64, 0));
    GradientPaint gradientpaint2 = new GradientPaint(0.0F, 0.0F, Color.red, 0.0F, 0.0F, new Color(64, 0, 0));

    barrenderer.setSeriesPaint(0, gradientpaint);
    barrenderer.setSeriesPaint(1, gradientpaint1);
    barrenderer.setSeriesPaint(2, gradientpaint2);

    barrenderer.setItemLabelGenerator(new LabelGenerator());
    barrenderer.setItemLabelsVisible(true);
    //ItemLabelPosition itemlabelposition = new ItemLabelPosition(ItemLabelAnchor.INSIDE12, TextAnchor.CENTER_RIGHT, TextAnchor.CENTER_RIGHT, -1.5707963267948966D);
    //barrenderer.setPositiveItemLabelPosition(itemlabelposition);

    ItemLabelPosition itemlabelposition1 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12,
            TextAnchor.CENTER_LEFT, TextAnchor.CENTER_LEFT, -1.5707963267948966D);
    barrenderer.setPositiveItemLabelPositionFallback(itemlabelposition1);

    CategoryAxis categoryaxis = categoryplot.getDomainAxis();
    categoryaxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
    /*   */
    this.setVariableValue("Chart", new JCommonDrawableRenderer(jfreechart));
}

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

protected JFreeChart createLegend(CategoryDataset dataset) {

    //  JFreeChart chart = ChartFactory.createAreaChart(
    JFreeChart chart = ChartFactory.createLineChart(chartTitle, // chart title
            domainLabel, // domain axis label
            rangeLabel, // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips
            false // urls
    );//from  w ww . ja  va  2  s .  c  o  m

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    chart.setBackgroundPaint(Color.white);
    CategoryPlot plot = chart.getCategoryPlot();

    StatisticalLineAndShapeRenderer renderer = new StatisticalLineAndShapeRenderer(true, false);
    renderer.setLegendItemLabelGenerator(
            new SOCRCategoryCellLabelGenerator(dataset, values_storage, SERIES_COUNT, CATEGORY_COUNT));
    plot.setRenderer(renderer);
    return chart;

}

From source file:UserInterface.AdministrativeRole.ReportsJPanel.java

private void resultSatisfactionBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_resultSatisfactionBtnActionPerformed
    // TODO add your handling code here:
    int notSatisfied = 0;
    int somewhatSatisfied = 0;
    int verySatisfied = 0;
    int notApplicable = 0;
    for (Organization organization : enterprise.getOrganizationDirectory().getOrganizationList()) {
        if (organization instanceof AdminOrganization) {
            for (FarmerFeedbackWorkRequest request : organization.getFeedbackWorkQueue()
                    .getFarmerFeedbackList()) {

                if (request.getResearchSolutionHelped().equalsIgnoreCase("Not Satisfied")) {
                    notSatisfied++;//from   ww  w.j av  a 2s .c om
                } else if (request.getResearchSolutionHelped().equalsIgnoreCase("Somewhat Satisfied")) {
                    somewhatSatisfied++;
                } else if (request.getResearchSolutionHelped().equalsIgnoreCase("Very Satisfied")) {
                    verySatisfied++;
                } else {
                    notApplicable++;
                }
            }

            break;
        }
    }

    DefaultCategoryDataset dataSet = new DefaultCategoryDataset();
    dataSet.setValue(notSatisfied, "", "Not Satisfied");
    dataSet.setValue(somewhatSatisfied, "", "Somewhat Satisfied");
    dataSet.setValue(verySatisfied, "", "Very Satisfied");
    dataSet.setValue(notApplicable, "", "Not Applicable");

    JFreeChart chart = ChartFactory.createBarChart("Research Result Satisfaction", "Satisfaction Level",
            "Number of Farmers", dataSet, PlotOrientation.VERTICAL, false, true, false);
    CategoryPlot plot = chart.getCategoryPlot();
    plot.setRangeGridlinePaint(Color.black);
    ChartFrame frame = new ChartFrame("Result Satisfaction", chart);
    frame.setVisible(true);
    frame.setSize(700, 500);
}

From source file:com.googlecode.refit.jenkins.ReFitGraph.java

/**
 * Creates a chart from the test result data set.
 * <p>/*  w  w  w  .  j  av  a 2  s  .co  m*/
 * The i-th row of the data set corresponds to the results from the i-th build.
 * Each row has columns 0, 1, 2 containing the number of failed, skipped and passed tests.
 * The chart stacks these values from bottom to top, joins the values for the same columns
 * with lines and fills the areas between the lines with given colours.
 * <p> 
 * TODO Find out if Jenkins core provides any caching for the chart or the data set.
 */
@Override
protected JFreeChart createGraph() {

    final JFreeChart chart = ChartFactory.createStackedAreaChart(null, // chart title
            null, // domain axis label 
            "count", // range axis label
            data, // data
            PlotOrientation.VERTICAL, // orientation
            false, // include legend
            true, // tooltips
            false // urls
    );

    chart.setBackgroundPaint(Color.white);

    final CategoryPlot plot = chart.getCategoryPlot();

    plot.setBackgroundPaint(Color.WHITE);
    plot.setOutlinePaint(null);
    plot.setForegroundAlpha(0.8f);
    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();
    ChartUtil.adjustChebyshev(data, rangeAxis);
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setAutoRange(true);

    StackedAreaRenderer ar = new StackedAreaRenderer2() {
        private static final long serialVersionUID = 1L;

        /**
         * Colour brush for the given data point.
         */
        @Override
        public Paint getItemPaint(int row, int column) {
            return super.getItemPaint(row, column);
        }

        /**
         * URL for the given data point, which gets opened when the user clicks on or near
         * the data point in the chart.
         */
        @Override
        public String generateURL(CategoryDataset dataset, int row, int column) {
            ChartLabel label = (ChartLabel) dataset.getColumnKey(column);
            return label.getUrl();
        }

        /**
         * Tooltip to be displayed on the chart when the user hovers at or near the
         * data point.
         * <p>
         * The tooltip has the format {@code #17 : 300 Passed}, indicating the build number
         * and the number of tests with the given result.
         */
        @Override
        public String generateToolTip(CategoryDataset dataset, int row, int column) {
            ChartLabel label = (ChartLabel) dataset.getColumnKey(column);
            TestResult result = label.getResult();
            String rowKey = (String) dataset.getRowKey(row);
            return result.getOwner().getDisplayName() + " : " + dataset.getValue(row, column) + " "
                    + rowKey.substring(1);
        }
    };
    plot.setRenderer(ar);

    // Define colours for the data points by column index
    ar.setSeriesPaint(0, ColorPalette.RED); // Failed
    ar.setSeriesPaint(1, ColorPalette.YELLOW); // Skipped
    ar.setSeriesPaint(2, ColorPalette.BLUE); // Passed

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

    return chart;
}

From source file:Interface.ResultadoJanela.java

public JFreeChart gerarGrafico(CategoryDataset dataSet) {
    JFreeChart chart = ChartFactory.createBarChart3D("Resultado da Localizao de Defeitos", //Titulo
            " ", // Eixo X
            "Probabilidade (%)", //Eixo Y
            dataSet, // Dados para o grafico
            PlotOrientation.VERTICAL, //Orientacao do grafico
            true, true, true); // exibir: legendas, tooltips, url
    chart.setBackgroundPaint(Color.getHSBColor(0, 0, (float) 0.835)); // Set the background colour of the chart

    CategoryPlot p = chart.getCategoryPlot(); // Get the Plot object for a bar graph
    p.setBackgroundPaint(Color.white); // Modify the plot background 
    p.setRangeGridlinePaint(Color.BLACK);

    CategoryAxis axis = p.getDomainAxis();
    axis.setTickLabelFont(new Font("Helvetica", Font.PLAIN, 10));
    axis.setMaximumCategoryLabelWidthRatio(1.0f);
    axis.setMaximumCategoryLabelLines(2);
    p.setDomainAxis(axis);/*from   w  w w.  jav  a2s  .com*/

    return chart;
}

From source file:vn.edu.vttu.ui.PanelStatiticsRevenue.java

private void showChart(String title, String begin, String end) {
    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    int row = tbResult.getRowCount();
    for (int i = 0; i < row; i++) {
        float value = 0;
        try {// w ww.  ja  va2s  . c om
            try {
                value = Float.parseFloat(String.valueOf(tbResult.getValueAt(i, 3)).trim().replaceAll("\\.", ""))
                        / 1000;
            } catch (Exception e) {
                value = Float.parseFloat(String.valueOf(tbResult.getValueAt(i, 3)).trim().replaceAll(",", ""))
                        / 1000;
            }
        } catch (Exception e) {
            value = 0;
        }
        String date = String.valueOf(tbResult.getValueAt(i, 0)).trim();

        dataset.addValue(value, "Doanh Thu", date);
    }

    JFreeChart chart = ChartFactory.createLineChart(
            "TH?NG K DOANH THU\nT " + title + " " + begin + " ?N " + title + " " + end, title,
            "S Ti?n(?n v: nghn ng)", dataset);
    CategoryPlot p = chart.getCategoryPlot();
    p.setRangeGridlinePaint(Color.black);
    ChartPanel CP = new ChartPanel(chart);
    pnChart.removeAll();
    pnChart.add(CP);
    pnChart.updateUI();
    pnChart.repaint();
    //ChartFrame frame = new ChartFrame("Thng k doanh thu", chart);
    //frame.setSize(450, 350);
    //frame.setVisible(true);
}

From source file:org.agmip.ui.afsirs.frames.GraphOutput.java

public void addGraph() {

    JFreeChart chart = ChartFactory.createBarChart("IRRIGATION REQUIREMENTS(INCHES)", "MONTH", "IRR",
            createDataset(0), PlotOrientation.VERTICAL, true, true, false);
    chart.setBackgroundPaint(Color.white);

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

    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(600, 270));
    jTabbedPane1.addTab("Irrigation Requirement", chartPanel);

    if (utils.getICODE() >= 0) {

        //JFreeChart chart1 = ChartFactory.createBarChart("IRRIGATION REQUIREMENTS(INCHES)", "BI-WEEK", "IRR", createDataset(1), PlotOrientation.VERTICAL, true, true, false);
        //JFreeChart chart2 = ChartFactory.createBarChart("IRRIGATION REQUIREMENTS(INCHES)", "WEEK", "IRR", createDataset(2), PlotOrientation.VERTICAL, true, true, false);
        JFreeChart chart1 = ChartFactory.createBarChart("IRRIGATION REQUIREMENTS(INCHES)", "1-In-10", "IRR",
                createDataset(1), PlotOrientation.VERTICAL, true, true, false);
        JFreeChart chart2 = ChartFactory.createBarChart("IRRIGATION REQUIREMENTS(INCHES)", "2-In-10", "IRR",
                createDataset(2), PlotOrientation.VERTICAL, true, true, false);

        chart1.setBackgroundPaint(Color.white);
        chart2.setBackgroundPaint(Color.white);

        plot = chart1.getCategoryPlot();
        plot.setBackgroundPaint(Color.lightGray);
        plot.setDomainGridlinePaint(Color.white);
        plot.setRangeGridlinePaint(Color.white);

        plot = chart2.getCategoryPlot();
        plot.setBackgroundPaint(Color.lightGray);
        plot.setDomainGridlinePaint(Color.white);
        plot.setRangeGridlinePaint(Color.white);

        ChartPanel chartPanel1 = new ChartPanel(chart1);
        chartPanel1.setPreferredSize(new java.awt.Dimension(600, 270));
        //jTabbedPane1.addTab("Bi-Week Graph", chartPanel1);
        jTabbedPane1.addTab("1-In-10", chartPanel1);

        ChartPanel chartPanel2 = new ChartPanel(chart2);
        chartPanel2.setPreferredSize(new java.awt.Dimension(600, 270));
        //jTabbedPane1.addTab("Weekly Graph", chartPanel2);
        jTabbedPane1.addTab("2-In-10", chartPanel2);
    }/*from w w  w  . ja va 2s . c  o  m*/
}

From source file:UserInterfaces.HAdministration.ReportDataJPanel.java

private void personneljButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_personneljButton3ActionPerformed
    // TODO add your handling code here:
    int timeofadmin = 0;
    int timeofnurse = 0;
    int timeofpathology = 0;
    int timeofphar = 0;
    int timeofphysician = 0;
    int timeofsurgeon = 0;

    for (WorkRequest workRequest : organization.getWorkQueue().getWorkRequestList()) {
        for (ErrorPerson ep : workRequest.getEpd().getErrorpersonlist()) {

            if (ep instanceof AdminstrationErrorPerson) {
                // if (ep.getEpt().getValue().equals(ErrorPerson.ErrorPersonType.ADMINSTRATION.getValue())) {
                timeofadmin = timeofadmin + 1;
            }/*from ww w . j a va2  s  .  c  o  m*/
            if (ep instanceof NurseErrorPerson) {
                timeofnurse = timeofnurse + 1;
            }
            if (ep instanceof PathologistriceErrorPerson) {
                timeofpathology = timeofpathology + 1;
            }
            if (ep instanceof PharmacistErrorPerson) {
                timeofphar = timeofphar + 1;
            }
            if (ep instanceof PhysicianErrorPerson) {
                timeofphysician = timeofphysician + 1;
            }
            if (ep instanceof SurgeonErrorPerson) {
                timeofsurgeon = timeofsurgeon + 1;

            }

            /*if (ep.getEpt().equals(ErrorPerson.ErrorPersonType.NURESE)) {
             timeofnurse = timeofnurse + 1;
             }
             if (ep.getEpt().equals(ErrorPerson.ErrorPersonType.PATHOLOGIST)) {
             timeofpathology = timeofpathology + 1;
             }
             if (ep.getEpt().equals(ErrorPerson.ErrorPersonType.PHARMACIST)) {
             timeofphar = timeofphar + 1;
             }
             if (ep.getEpt().equals(ErrorPerson.ErrorPersonType.PHYSICIAN)) {
             timeofphysician = timeofphysician + 1;
             }
             if (ep.getEpt().equals(ErrorPerson.ErrorPersonType.SURGEON)) {
             timeofsurgeon = timeofsurgeon + 1;
             }*/
        }
    }
    ReportToReporter report = organization.getReport();
    report.setTimeofadmin(timeofadmin);
    report.setTimeofnurse(timeofnurse);
    report.setTimeofpathology(timeofpathology);
    report.setTimeofphar(timeofphar);
    report.setTimeofphysician(timeofphysician);
    report.setTimeofsurgeon(timeofsurgeon);
    report.setStatus("success");

    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    dataset.addValue(timeofadmin, "Adminstration", "Adminstration");
    dataset.addValue(timeofnurse, "Nurse", "Nurse");
    dataset.addValue(timeofpathology, "Pathologist", "Pathologist");
    dataset.addValue(timeofphar, "Pharmacist", "Pharmacist");
    dataset.addValue(timeofphysician, "Physician", "Physician");
    dataset.addValue(timeofsurgeon, "Surgeon", "Surgeon");
    //dataset.setValue(80, "masd", "sss");

    JFreeChart chart = ChartFactory.createBarChart("Personnel", "Position", "Times", dataset,
            PlotOrientation.VERTICAL, false, true, false);
    CategoryPlot plot = chart.getCategoryPlot();
    plot.setRangeGridlinePaint(Color.WHITE);
    ChartFrame frame = new ChartFrame("Chart for ERROR", chart);
    frame.setVisible(true);
    frame.setSize(900, 700);

    for (Network network : es.getNetworkList()) {
        for (Enterprise e : network.getEd().getEnterprisesList()) {
            if (e.getOrgName().equals(enterprise.getOrgName())) {
                for (Enterprise en : network.getEd().getEnterprisesList()) {
                    if (e instanceof HospitalEnterprise || e instanceof ClinicEnterprise) {
                        e.setReport(report);
                    }
                }
            }

        }

    }

}

From source file:se.backede.jeconomix.forms.report.TransactionReport.java

public void addLineChart(Map<String, List<TransactionReportDto>> reports, Boolean average) {
    JFreeChart lineChart = ChartFactory.createLineChart("TOTAL", "MONTH", "Kr",
            ReportUtils.createDataset(reports, average), PlotOrientation.VERTICAL, true, true, true);

    ChartPanel chartPanel = new ChartPanel(lineChart);
    chartPanel.setPreferredSize(new java.awt.Dimension(lineChartPanel.getWidth(), lineChartPanel.getHeight()));

    CategoryAxis axis = lineChart.getCategoryPlot().getDomainAxis();
    CategoryItemRenderer renderer = lineChart.getCategoryPlot().getRenderer();

    ItemLabelPosition position = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE1, TextAnchor.HALF_ASCENT_CENTER,
            TextAnchor.BOTTOM_CENTER, 0);
    renderer.setBasePositiveItemLabelPosition(position);

    renderer.setBaseItemLabelGenerator(new CategoryItemLabelGenerator() {

        @Override//from www  .  jav a2s .c  o m
        public String generateLabel(CategoryDataset dataset, int series, int category) {
            if (average) {
                if (series == 0) {
                    Number value = dataset.getValue(series, category);
                    String result = value.toString(); // could apply formatting here
                    return result;
                }
            } else {
                Number value = dataset.getValue(series, category);
                String result = value.toString(); // could apply formatting here
                return result;
            }
            return null;
        }

        @Override
        public String generateRowLabel(CategoryDataset cd, int i) {
            return null;
        }

        @Override
        public String generateColumnLabel(CategoryDataset cd, int i) {
            return null;
        }
    });

    renderer.setBaseItemLabelsVisible(true);
    lineChartPanel.setLayout(new BorderLayout());
    lineChartPanel.add(chartPanel, BorderLayout.NORTH);
}

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

protected JFreeChart createLegend(CategoryDataset dataset) {

    //  JFreeChart chart = ChartFactory.createAreaChart(
    JFreeChart chart = ChartFactory.createBarChart(chartTitle, // chart title
            domainLabel, // domain axis label
            rangeLabel, // 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 om

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    chart.setBackgroundPaint(Color.white);
    CategoryPlot plot = chart.getCategoryPlot();

    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    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);
    // renderer.setDrawOutlines(true);
    // renderer.setUseFillPaint(true);
    // renderer.setFillPaint(Color.white);
    renderer.setLegendItemLabelGenerator(new SOCRCategorySeriesLabelGenerator());
    return chart;

}