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.talend.dataprofiler.chart.util.TopChartFactory.java

/**
 * create bar chart.//w  ww.ja  v a  2  s .  c om
 * 
 * @param titile
 * @param dataset
 * @return
 */
public static JFreeChart createBarChartByKCD(String title, CategoryDataset dataset, Object cusmomerDataset) {
    // ADD msjian TDQ-5112 2012-4-10: after upgrate to jfreechart-1.0.12.jar, change the default chart wallPaint
    ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme());
    // TDQ-5112~
    JFreeChart createBarChart = ChartFactory.createBarChart(null, Messages.getString("TopChartFactory.Value"), //$NON-NLS-1$
            title, dataset, PlotOrientation.HORIZONTAL, false, false, false);

    CategoryPlot plot = createBarChart.getCategoryPlot();
    if (cusmomerDataset != null) {
        plot.setDataset(1, new EncapsulationCumstomerDataset(dataset, cusmomerDataset));
    }

    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setTickLabelPaint(NULL_FIELD, Color.RED);
    domainAxis.setTickLabelPaint(NULL_FIELD2, Color.RED);
    domainAxis.setTickLabelPaint(EMPTY_FIELD, Color.RED);

    // ADD TDQ-5251 msjian 2012-7-31: do not display the shadow
    BarRenderer renderer = new TalendBarRenderer(false, ChartDecorator.COLOR_LIST);
    renderer.setShadowVisible(false);
    // TDQ-5251~

    plot.setRenderer(renderer);
    return createBarChart;
}

From source file:com.opensourcestrategies.crmsfa.reports.JFreeCrmsfaCharts.java

/**
 * Open Cases snapshot.  Description at http://www.opentaps.org/docs/index.php/CRMSFA_Dashboard
 * Note that this counts all the cases in the system for now.
 *///w ww  . j  ava  2 s.  c om
public static String createOpenCasesChart(Delegator delegator, Locale locale)
        throws GenericEntityException, IOException {
    Map uiLabelMap = UtilMessage.getUiLabels(locale);

    // create the dataset
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    // get all case statuses that are not "closed" (this is dynamic because statuses may be added at run time)
    List<GenericValue> statuses = ReportHelper.findCasesStagesForDashboardReporting(delegator);

    // Report number of cases for each status
    for (GenericValue status : statuses) {
        String statusId = status.getString("statusId");
        long count = delegator.findCountByCondition("CustRequest",
                EntityCondition.makeCondition("statusId", EntityOperator.EQUALS, statusId), null);
        dataset.addValue(count, "", (String) status.get("description", locale));
    }

    // set up the chart
    JFreeChart chart = ChartFactory.createBarChart((String) uiLabelMap.get("CrmOpenCases"), // chart title
            null, // domain axis label
            null, // range axis label
            dataset, // data
            PlotOrientation.HORIZONTAL, // orientation
            false, // include legend
            true, // tooltips
            false // urls
    );
    chart.setBackgroundPaint(Color.white);
    chart.setBorderVisible(true);
    chart.setPadding(new RectangleInsets(5.0, 5.0, 5.0, 5.0));

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

    // get the bar renderer to put effects on the bars
    final BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false); // disable bar outlines

    // set up gradient paint on bar
    final GradientPaint gp = new GradientPaint(0.0f, 0.0f, new Color(246, 227, 206), 0.0f, 0.0f,
            new Color(204, 153, 102));
    renderer.setSeriesPaint(0, gp);

    // change the auto tick unit selection to integer units only...
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    // tilt the category labels so they fit
    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0));

    // save as a png and return the file name
    return ServletUtilities.saveChartAsPNG(chart, 360, 300, null);
}

From source file:com.opensourcestrategies.crmsfa.reports.JFreeCrmsfaCharts.java

/**
 * Team Member Activity Snapshot.  Description at http://www.opentaps.org/docs/index.php/CRMSFA_Dashboard
 * Note that this counts all the team members in the system for now.
 *//*from  w w  w.  java2s  . c  o  m*/
public static String createActivitiesByTeamMemberChart(Delegator delegator, Locale locale)
        throws GenericEntityException, IOException {
    Map uiLabelMap = UtilMessage.getUiLabels(locale);

    // create the dataset
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    // get all team members (read the TODO in this function)
    List<GenericValue> teamMembers = TeamHelper.getTeamMembersForOrganization(delegator);

    // condition to count activities
    EntityCondition conditions = EntityCondition.makeCondition(EntityOperator.AND,
            EntityCondition.makeCondition("statusId", EntityOperator.EQUALS, "PRTYASGN_ASSIGNED"),
            EntityCondition.makeCondition("currentStatusId", EntityOperator.NOT_IN,
                    UtilActivity.ACT_STATUSES_COMPLETED),
            EntityUtil.getFilterByDateExpr());

    // condition to count pending outbound emails
    EntityCondition commConditions = EntityCondition.makeCondition(EntityOperator.AND,
            EntityCondition.makeCondition("communicationEventTypeId", EntityOperator.EQUALS,
                    "EMAIL_COMMUNICATION"),
            EntityCondition.makeCondition("workEffortTypeId", EntityOperator.EQUALS, "TASK"),
            EntityCondition.makeCondition("workEffortPurposeTypeId", EntityOperator.EQUALS, "WEPT_TASK_EMAIL"),
            EntityCondition.makeCondition("currentStatusId", EntityOperator.IN,
                    UtilMisc.toList("TASK_SCHEDULED", "TASK_STARTED")),
            EntityCondition.makeCondition("assignmentStatusId", EntityOperator.EQUALS, "PRTYASGN_ASSIGNED"),
            EntityUtil.getFilterByDateExpr());

    // count active work efforts for each team member
    for (GenericValue member : teamMembers) {
        String partyId = member.getString("partyId");
        EntityCondition memberCond = EntityCondition.makeCondition("partyId", EntityOperator.EQUALS, partyId);
        long count = delegator.findCountByCondition("WorkEffortAndPartyAssign", memberCond, null);

        // subtract outbound emails
        EntityCondition commCond = EntityCondition.makeCondition("partyId", EntityOperator.EQUALS, partyId);
        count -= delegator.findCountByCondition("WorkEffortPartyAssignCommEvent", commCond, null);

        // bar will be the name of the team member
        StringBuffer name = new StringBuffer();
        name.append(member.get("lastName")).append(", ").append(member.get("firstName"));
        dataset.addValue(count, "", name.toString());
    }

    // set up the chart
    JFreeChart chart = ChartFactory.createBarChart((String) uiLabelMap.get("CrmActivitiesByTeamMember"), // chart title
            null, // domain axis label
            null, // range axis label
            dataset, // data
            PlotOrientation.HORIZONTAL, // orientation
            false, // include legend
            true, // tooltips
            false // urls
    );
    chart.setBackgroundPaint(Color.white);
    chart.setBorderVisible(true);
    chart.setPadding(new RectangleInsets(5.0, 5.0, 5.0, 5.0));

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

    // get the bar renderer to put effects on the bars
    final BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false); // disable bar outlines

    // set up gradient paint on bar
    final GradientPaint gp = new GradientPaint(0.0f, 0.0f, new Color(230, 230, 230), 0.0f, 0.0f,
            new Color(153, 153, 153));
    renderer.setSeriesPaint(0, gp);

    // by default the gradient is vertical, but we can make it horizontal like this
    renderer.setGradientPaintTransformer(
            new StandardGradientPaintTransformer(GradientPaintTransformType.HORIZONTAL));

    // change the auto tick unit selection to integer units only...
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    // save as a png and return the file name (vertical height depends on size of team members)
    return ServletUtilities.saveChartAsPNG(chart, 360, 100 + 25 * teamMembers.size(), null);
}

From source file:org.apache.qpid.disttest.charting.chartbuilder.CategoryStrokeAndPaintApplier.java

@Override
public void setSeriesStroke(int seriesIndex, Stroke stroke, JFreeChart targetChart) {
    targetChart.getCategoryPlot().getRenderer().setSeriesStroke(seriesIndex, stroke);
}

From source file:org.apache.qpid.disttest.charting.chartbuilder.CategoryStrokeAndPaintApplier.java

@Override
public void setSeriesPaint(int seriesIndex, Color colour, JFreeChart targetChart) {
    targetChart.getCategoryPlot().getRenderer().setSeriesPaint(seriesIndex, colour);
}

From source file:eu.cassandra.training.utils.ChartUtils.java

/**
 * This function is used for the visualization of two Area Diagrams.
 * //from w ww.j a va  2s  . co m
 * @param title
 *          The title of the chart.
 * @param x
 *          The unit on the X axis of the chart.
 * @param y
 *          The unit on the Y axis of the chart.
 * @param doubles
 *          The array of values of the first array.
 * @param doubles2
 *          The array of values of the second array.
 * @return a chart panel with the graphical representation.
 */
public static ChartPanel createArea(String title, String x, String y, Double[] doubles, Double[] doubles2) {
    JFreeChart chart = null;
    if (doubles.length != doubles2.length) {
        System.out.println("ERROR with lengths.");
    } else {
        Double[][] data = new Double[2][doubles.length];

        data[0] = doubles;
        data[1] = doubles2;

        final CategoryDataset dataset = DatasetUtilities.createCategoryDataset("Power ", "", data);

        chart = ChartFactory.createAreaChart(title, x, y, dataset, PlotOrientation.VERTICAL, true, true, false);

        chart.setBackgroundPaint(Color.white);

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

        CategoryAxis domainAxis = plot.getDomainAxis();
        domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
        // domainAxis.setTickUnit(new NumberTickUnit(10));
        NumberAxis numberaxis = (NumberAxis) plot.getRangeAxis();
        numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    }
    return new ChartPanel(chart);
}

From source file:com.voterData.graph.Graph.java

public static JFreeChart getAgeDistChart2008(Map<String, Double> dataMap) {
    DefaultCategoryDataset defaultcategorydataset = new DefaultCategoryDataset();
    for (String key : dataMap.keySet()) {
        if (key.equals("Age17_Dem_2008")) {
            defaultcategorydataset.addValue(dataMap.get(key), "DEM", "17-25 Yrs");
        } else if (key.equals("Age17_Rep_2008")) {
            defaultcategorydataset.addValue(dataMap.get(key), "REP", "17-25 Yrs");
        } else if (key.equals("Age17_Una_2008")) {
            defaultcategorydataset.addValue(dataMap.get(key), "UNA", "17-25 Yrs");
        } else if (key.equals("Age26_Dem_2008")) {
            defaultcategorydataset.addValue(dataMap.get(key), "DEM", "26-35 Yrs");
        } else if (key.equals("Age26_Rep_2008")) {
            defaultcategorydataset.addValue(dataMap.get(key), "REP", "26-35 Yrs");
        } else if (key.equals("Age26_Una_2008")) {
            defaultcategorydataset.addValue(dataMap.get(key), "UNA", "26-35 Yrs");
        } else if (key.equals("Age36_Dem_2008")) {
            defaultcategorydataset.addValue(dataMap.get(key), "DEM", "36-50 Yrs");
        } else if (key.equals("Age36_Rep_2008")) {
            defaultcategorydataset.addValue(dataMap.get(key), "REP", "36-50 Yrs");
        } else if (key.equals("Age36_Una_2008")) {
            defaultcategorydataset.addValue(dataMap.get(key), "UNA", "36-50 Yrs");
        } else if (key.equals("Age51_Dem_2008")) {
            defaultcategorydataset.addValue(dataMap.get(key), "DEM", "51-65 Yrs");
        } else if (key.equals("Age51_Rep_2008")) {
            defaultcategorydataset.addValue(dataMap.get(key), "REP", "51-65 Yrs");
        } else if (key.equals("Age51_Una_2008")) {
            defaultcategorydataset.addValue(dataMap.get(key), "UNA", "51-65 Yrs");
        } else if (key.equals("Age65_Dem_2008")) {
            defaultcategorydataset.addValue(dataMap.get(key), "DEM", ">65 Yrs");
        } else if (key.equals("Age65_Rep_2008")) {
            defaultcategorydataset.addValue(dataMap.get(key), "REP", ">65 Yrs");
        } else if (key.equals("Age65_Una_2008")) {
            defaultcategorydataset.addValue(dataMap.get(key), "UNA", ">65 Yrs");
        }//from w  w  w . j  av  a 2 s  .  co m
    }
    JFreeChart jfreechart = ChartFactory.createBarChart("Age based Distribution - Year 2008", "Age in Years",
            " Votes in %", defaultcategorydataset, PlotOrientation.VERTICAL, true, true, false);
    jfreechart.setBackgroundPaint(Color.white);
    CategoryPlot cplot = (CategoryPlot) jfreechart.getPlot();
    cplot.setBackgroundPaint(Color.lightGray);//change background color
    //set  bar chart color
    // ((BarRenderer) cplot.getRenderer()).setBarPainter(new StandardBarPainter());
    BarRenderer r = (BarRenderer) jfreechart.getCategoryPlot().getRenderer();
    r.setSeriesPaint(0, Color.green);
    r.setSeriesPaint(1, Color.red);
    r.setSeriesPaint(2, Color.blue);
    return jfreechart;

}

From source file:com.voterData.graph.Graph.java

public static JFreeChart getAgeDistChart2012(Map<String, Double> dataMap) {
    DefaultCategoryDataset defaultcategorydataset = new DefaultCategoryDataset();
    for (String key : dataMap.keySet()) {
        if (key.equals("Age17_Dem_2012")) {
            defaultcategorydataset.addValue(dataMap.get(key), "DEM", "17-25 Yrs");
        } else if (key.equals("Age17_Rep_2012")) {
            defaultcategorydataset.addValue(dataMap.get(key), "REP", "17-25 Yrs");
        } else if (key.equals("Age17_Una_2012")) {
            defaultcategorydataset.addValue(dataMap.get(key), "UNA", "17-25 Yrs");
        } else if (key.equals("Age26_Dem_2012")) {
            defaultcategorydataset.addValue(dataMap.get(key), "DEM", "26-35 Yrs");
        } else if (key.equals("Age26_Rep_2012")) {
            defaultcategorydataset.addValue(dataMap.get(key), "REP", "26-35 Yrs");
        } else if (key.equals("Age26_Una_2012")) {
            defaultcategorydataset.addValue(dataMap.get(key), "UNA", "26-35 Yrs");
        } else if (key.equals("Age36_Dem_2012")) {
            defaultcategorydataset.addValue(dataMap.get(key), "DEM", "36-50 Yrs");
        } else if (key.equals("Age36_Rep_2012")) {
            defaultcategorydataset.addValue(dataMap.get(key), "REP", "36-50 Yrs");
        } else if (key.equals("Age36_Una_2012")) {
            defaultcategorydataset.addValue(dataMap.get(key), "UNA", "36-50 Yrs");
        } else if (key.equals("Age51_Dem_2012")) {
            defaultcategorydataset.addValue(dataMap.get(key), "DEM", "51-65 Yrs");
        } else if (key.equals("Age51_Rep_2012")) {
            defaultcategorydataset.addValue(dataMap.get(key), "REP", "51-65 Yrs");
        } else if (key.equals("Age51_Una_2012")) {
            defaultcategorydataset.addValue(dataMap.get(key), "UNA", "51-65 Yrs");
        } else if (key.equals("Age65_Dem_2012")) {
            defaultcategorydataset.addValue(dataMap.get(key), "DEM", ">65 Yrs");
        } else if (key.equals("Age65_Rep_2012")) {
            defaultcategorydataset.addValue(dataMap.get(key), "REP", ">65 Yrs");
        } else if (key.equals("Age65_Una_2012")) {
            defaultcategorydataset.addValue(dataMap.get(key), "UNA", ">65 Yrs");
        }//  w  w w  .  j  av a 2s  . c om
    }
    JFreeChart jfreechart = ChartFactory.createBarChart("Age based Distribution - Year 2012", "Age in Years",
            " Votes in %", defaultcategorydataset, PlotOrientation.VERTICAL, true, true, false);
    jfreechart.setBackgroundPaint(Color.white);
    CategoryPlot cplot = (CategoryPlot) jfreechart.getPlot();
    cplot.setBackgroundPaint(Color.lightGray);//change background color
    //set  bar chart color
    // ((BarRenderer) cplot.getRenderer()).setBarPainter(new StandardBarPainter());
    BarRenderer r = (BarRenderer) jfreechart.getCategoryPlot().getRenderer();
    r.setSeriesPaint(0, Color.blue);
    r.setSeriesPaint(1, Color.green);
    r.setSeriesPaint(2, Color.red);
    return jfreechart;

}

From source file:Reportes.ChartCustomizer.java

@Override
public void customize(JFreeChart chart, ReportParameters reportParameters) {
    CategoryAxis domainAxis = chart.getCategoryPlot().getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 2));
}

From source file:org.apache.qpid.disttest.charting.chartbuilder.CategoryStrokeAndPaintApplier.java

@Override
public void setSeriesShape(final int seriesIndex, final java.awt.Shape shape, final JFreeChart targetChart) {
    CategoryItemRenderer renderer = targetChart.getCategoryPlot().getRenderer();
    if (renderer instanceof LineAndShapeRenderer) {
        LineAndShapeRenderer lineAndShapeRenderer = (LineAndShapeRenderer) renderer;
        lineAndShapeRenderer.setSeriesShapesVisible(seriesIndex, true);
        lineAndShapeRenderer.setSeriesShape(seriesIndex, shape);
    }/*from  www .  j a  v a2  s .  c o m*/
}