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:net.sf.dynamicreports.test.jasper.chart.GroupedStackedBarChartData3Test.java

private void testMap(JFreeChart chart, String... groups) {
    GroupedStackedBarRenderer renderer = (GroupedStackedBarRenderer) chart.getCategoryPlot().getRenderer();
    try {/*from w w  w .jav  a  2  s .  c  o m*/
        Field field = renderer.getClass().getDeclaredField("seriesToGroupMap");
        field.setAccessible(true);
        KeyToGroupMap map = (KeyToGroupMap) field.get(renderer);
        Assert.assertEquals("map", groups.length, map.getGroupCount());
        List<?> groups2 = map.getGroups();
        for (int i = 0; i < groups2.size(); i++) {
            Assert.assertEquals("map", groups[i], groups2.get(i));
        }
    } catch (Exception e) {
        e.printStackTrace();
        Assert.fail(e.getMessage());
    }
}

From source file:net.sf.dynamicreports.test.jasper.chart.GroupedStackedBarChartTest.java

@Override
public void test() {
    super.test();

    numberOfPagesTest(1);// w w  w  .j  a  va 2 s.co  m

    JFreeChart chart = getChart("summary.chart1", 0);
    CategoryPlot categoryPlot = chart.getCategoryPlot();
    Assert.assertEquals("renderer", GroupedStackedBarRenderer.class, categoryPlot.getRenderer().getClass());
    Assert.assertTrue("show labels", categoryPlot.getRenderer().getBaseItemLabelsVisible());
    Assert.assertFalse("show tick labels", categoryPlot.getDomainAxis().isTickLabelsVisible());
    Assert.assertFalse("show tick marks", categoryPlot.getDomainAxis().isTickMarksVisible());

    chart = getChart("summary.chart2", 0);
    Axis axis = chart.getCategoryPlot().getDomainAxis();
    Assert.assertEquals("category label", "category", axis.getLabel());
    Assert.assertEquals("category label color", Color.BLUE, axis.getLabelPaint());
    Assert.assertEquals("category label font", new Font("Arial", Font.BOLD, 10), axis.getLabelFont());
    Assert.assertEquals("tick label color", Color.CYAN, axis.getTickLabelPaint());
    Assert.assertEquals("tick label font", new Font("Arial", Font.ITALIC, 10), axis.getTickLabelFont());
    CategoryLabelPosition labelPosition = chart.getCategoryPlot().getDomainAxis().getCategoryLabelPositions()
            .getLabelPosition(RectangleEdge.LEFT);
    Assert.assertEquals("plot label rotation", (45d / 180) * Math.PI, labelPosition.getAngle());
    Assert.assertEquals("line color", Color.LIGHT_GRAY, axis.getAxisLinePaint());

    chart = getChart("summary.chart3", 0);
    axis = chart.getCategoryPlot().getRangeAxis();
    Assert.assertEquals("value label", "value", axis.getLabel());
    Assert.assertEquals("value label color", Color.BLUE, axis.getLabelPaint());
    Assert.assertEquals("value label font", new Font("Arial", Font.BOLD, 10), axis.getLabelFont());
    Assert.assertEquals("tick label color", Color.CYAN, axis.getTickLabelPaint());
    Assert.assertEquals("tick label font", new Font("Arial", Font.ITALIC, 10), axis.getTickLabelFont());
    Assert.assertEquals("tick label mask", "10.00", ((NumberAxis) axis).getNumberFormatOverride().format(10));
    Assert.assertEquals("line color", Color.LIGHT_GRAY, axis.getAxisLinePaint());
    Assert.assertEquals("range min value", 1d, ((ValueAxis) axis).getLowerBound());
    Assert.assertEquals("range max value", 15d, ((ValueAxis) axis).getUpperBound());
}

From source file:net.sf.dynamicreports.test.jasper.chart.StackedBar3DChartTest.java

@Override
public void test() {
    super.test();

    numberOfPagesTest(1);//  ww  w  . j a v a  2  s .  c o m

    JFreeChart chart = getChart("summary.chart1", 0);
    CategoryPlot categoryPlot = chart.getCategoryPlot();
    Assert.assertEquals("renderer", StackedBarRenderer3D.class, categoryPlot.getRenderer().getClass());
    BarRenderer3D renderer = (BarRenderer3D) categoryPlot.getRenderer();
    Assert.assertTrue("show labels", renderer.getBaseItemLabelsVisible());
    Assert.assertEquals("x offset", 2d, renderer.getXOffset());
    Assert.assertEquals("y offset", 3d, renderer.getYOffset());

    chart = getChart("summary.chart2", 0);
    Axis axis = chart.getCategoryPlot().getDomainAxis();
    Assert.assertEquals("category label", "category", axis.getLabel());
    Assert.assertEquals("category label color", Color.BLUE, axis.getLabelPaint());
    Assert.assertEquals("category label font", new Font("Arial", Font.BOLD, 10), axis.getLabelFont());
    Assert.assertEquals("tick label color", Color.CYAN, axis.getTickLabelPaint());
    Assert.assertEquals("tick label font", new Font("Arial", Font.ITALIC, 10), axis.getTickLabelFont());
    CategoryLabelPosition labelPosition = chart.getCategoryPlot().getDomainAxis().getCategoryLabelPositions()
            .getLabelPosition(RectangleEdge.LEFT);
    Assert.assertEquals("plot label rotation", (45d / 180) * Math.PI, labelPosition.getAngle());
    Assert.assertEquals("line color", Color.LIGHT_GRAY, axis.getAxisLinePaint());

    chart = getChart("summary.chart3", 0);
    axis = chart.getCategoryPlot().getRangeAxis();
    Assert.assertEquals("value label", "value", axis.getLabel());
    Assert.assertEquals("value label color", Color.BLUE, axis.getLabelPaint());
    Assert.assertEquals("value label font", new Font("Arial", Font.BOLD, 10), axis.getLabelFont());
    Assert.assertEquals("tick label color", Color.CYAN, axis.getTickLabelPaint());
    Assert.assertEquals("tick label font", new Font("Arial", Font.ITALIC, 10), axis.getTickLabelFont());
    Assert.assertEquals("tick label mask", "10.00", ((NumberAxis) axis).getNumberFormatOverride().format(10));
    Assert.assertEquals("line color", Color.LIGHT_GRAY, axis.getAxisLinePaint());
    Assert.assertEquals("range min value", 1d, ((ValueAxis) axis).getLowerBound());
    Assert.assertEquals("range max value", 15d, ((ValueAxis) axis).getUpperBound());
}

From source file:net.sf.dynamicreports.test.jasper.chart.GanttChartTest.java

@Override
public void test() {
    super.test();

    numberOfPagesTest(1);/* ww w .j  a  v  a2 s. c o  m*/

    JFreeChart chart = getChart("summary.chart1", 0);
    CategoryPlot categoryPlot = chart.getCategoryPlot();
    Assert.assertEquals("renderer", GanttRenderer.class, categoryPlot.getRenderer().getClass());
    Assert.assertTrue("show labels", categoryPlot.getRenderer().getBaseItemLabelsVisible());
    Assert.assertFalse("show tick labels", categoryPlot.getDomainAxis().isTickMarksVisible());
    Assert.assertFalse("show tick marks", categoryPlot.getDomainAxis().isTickLabelsVisible());
    ganttChartDataTest(chart, "label", new String[] { "task1", "task2", "task3" },
            new Object[][] { { toDate(2011, 1, 1), toDate(2011, 1, 8), 1d },
                    { toDate(2011, 1, 10), toDate(2011, 1, 15), 0.5d },
                    { toDate(2011, 1, 15), toDate(2011, 1, 25), 0.8d } });
    ganttChartDataTest(chart, "serie1", new String[] { "task1", "task2", "task3" },
            new Object[][] { { toDate(2011, 1, 2), toDate(2011, 1, 9), null },
                    { toDate(2011, 1, 8), toDate(2011, 1, 14), null },
                    { toDate(2011, 1, 16), toDate(2011, 1, 20), null } });

    chart = getChart("summary.chart2", 0);
    Axis axis = chart.getCategoryPlot().getDomainAxis();
    Assert.assertEquals("task label", "task", axis.getLabel());
    Assert.assertEquals("task label color", Color.BLUE, axis.getLabelPaint());
    Assert.assertEquals("task label font", new Font("Arial", Font.BOLD, 10), axis.getLabelFont());
    Assert.assertEquals("tick label color", Color.CYAN, axis.getTickLabelPaint());
    Assert.assertEquals("tick label font", new Font("Arial", Font.ITALIC, 10), axis.getTickLabelFont());
    CategoryLabelPosition labelPosition = chart.getCategoryPlot().getDomainAxis().getCategoryLabelPositions()
            .getLabelPosition(RectangleEdge.LEFT);
    Assert.assertEquals("plot label rotation", (45d / 180) * Math.PI, labelPosition.getAngle());
    Assert.assertEquals("line color", Color.LIGHT_GRAY, axis.getAxisLinePaint());

    chart = getChart("summary.chart3", 0);
    axis = chart.getCategoryPlot().getRangeAxis();
    Assert.assertEquals("time label", "time", axis.getLabel());
    Assert.assertEquals("time label color", Color.BLUE, axis.getLabelPaint());
    Assert.assertEquals("time label font", new Font("Arial", Font.BOLD, 10), axis.getLabelFont());
    Assert.assertEquals("tick label color", Color.CYAN, axis.getTickLabelPaint());
    Assert.assertEquals("tick label font", new Font("Arial", Font.ITALIC, 10), axis.getTickLabelFont());
    Assert.assertEquals("line color", Color.LIGHT_GRAY, axis.getAxisLinePaint());
}

From source file:org.pentaho.plugin.jfreereport.reportcharts.WaterfallChartExpressions.java

protected JFreeChart computeCategoryChart(final CategoryDataset dataset) {
    final JFreeChart chart = ChartFactory.createWaterfallChart(computeTitle(), getCategoryAxisLabel(),
            getValueAxisLabel(), dataset, computePlotOrientation(), isShowLegend(), false, false);
    chart.getCategoryPlot().setDomainAxis(new FormattedCategoryAxis(getCategoryAxisLabel(),
            getCategoricalAxisMessageFormat(), getRuntime().getResourceBundleFactory().getLocale()));
    return chart;
}

From source file:Visuals.AreaChart.java

public ChartPanel drawAreaChart() {
    DefaultCategoryDataset areadataset = new DefaultCategoryDataset();
    areadataset.addValue(new Double(successCount), "Success", "Success (" + successCount + ")");
    areadataset.addValue(new Double(failCount), "Fail", "Fail (" + failCount + ")");

    JFreeChart areachart = ChartFactory.createBarChart("", // Title  
            "Result", "Attempts", areadataset // Dataset   
    );/*from   w w w . j av  a2  s . co  m*/

    final CategoryPlot plot = areachart.getCategoryPlot();
    CategoryItemRenderer renderer = new CustomRendererAudit();

    areachart.removeLegend();
    plot.setRenderer(renderer);
    areachart.getCategoryPlot().setRenderer(renderer);
    //        plot.set("Success", new Color(230, 27, 27)); 
    //        plot.setSectionPaint("Fail", new Color(230, 90, 27)); 
    final CategoryPlot plotx = areachart.getCategoryPlot();
    ((BarRenderer) plotx.getRenderer()).setBarPainter(new StandardBarPainter());

    plotx.setBackgroundPaint(new Color(210, 234, 243));
    ChartPanel chartPanel = new ChartPanel(areachart);
    return chartPanel;
}

From source file:jmbench.plots.SummaryWhiskerPlot.java

public JFreeChart createChart() {
    JFreeChart chart = ChartFactory.createBoxAndWhiskerChart(title, "Matrix Libraries", "Relative Performance",
            dataSet, true);/* w  w w  . j  a  va2s.  c o  m*/
    CategoryPlot plot = chart.getCategoryPlot();
    plot.setDomainGridlinesVisible(true);
    plot.setBackgroundPaint(new Color(230, 230, 230));
    plot.setDomainGridlinePaint(new Color(50, 50, 50, 50));
    plot.setDomainGridlineStroke(new BasicStroke(78f));

    chart.getTitle().setFont(new Font("Times New Roman", Font.BOLD, 24));

    String foo = "( Higher is Better )";
    if (subtitle != null)
        foo += "      ( " + subtitle + " )";

    chart.addSubtitle(new TextTitle(foo, new Font("SansSerif", Font.ITALIC, 12)));

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

    return chart;
}

From source file:presentation.webgui.vitroappservlet.VisualStyles.java

protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    HttpSession session = request.getSession();
    this.uStyleId = request.getParameter("suid");
    Model3dStylesList myStylesIndex = Model3dStylesList.getModel3dStylesList();
    Model3dStylesEntry currStyleEntry = myStylesIndex.getStyleWithId(this.uStyleId);
    if (currStyleEntry != null) {
        response.setContentType("image/png");
        OutputStream out = response.getOutputStream();
        try {/* w  ww  . j a v  a 2s .com*/
            JFreeChart chart = StyleCreator.createDatasetAndChart(currStyleEntry);

            int chartHeight = 40;
            if (chart.getCategoryPlot().getDataset().getColumnKeys().size() > 1) {
                chartHeight = chart.getCategoryPlot().getDataset().getColumnKeys().size() * 22;
            }
            ChartUtilities.writeChartAsPNG(out, chart, 300, chartHeight);
        } catch (Exception e) {
            System.err.println(e.toString());
            response.setContentType("text/html");
            PrintWriter outPrintWriter = response.getWriter();
            outPrintWriter.print("<b>Error</b>:" + e.toString());
            outPrintWriter.flush();
            outPrintWriter.close();
        } finally {
            out.close();
        }
        return;
    } else {
        response.setContentType("text/html");
        PrintWriter outPrintWriter = response.getWriter();
        outPrintWriter.print("<b>No style defined</b>");
        outPrintWriter.flush();
        outPrintWriter.close();
    }
}

From source file:net.sf.dynamicreports.test.jasper.chart.GroupedStackedBarChartData3Test.java

@Override
public void test() {
    super.test();

    numberOfPagesTest(1);//from  w ww .ja v a 2 s  . com

    String[] categories = new String[] { "value1" };
    String[] series = new String[] {
            "group1" + GroupedStackedBarRendererCustomizer.GROUP_SERIES_KEY + "series1",
            "group2" + GroupedStackedBarRendererCustomizer.GROUP_SERIES_KEY + "series1",
            "group3" + GroupedStackedBarRendererCustomizer.GROUP_SERIES_KEY + "series1" };
    Number[][] values = new Number[][] { { 1d, 2d, 3d } };
    chartCountTest("groupFooter.chart1", 2);
    chartCategoryCountTest("groupFooter.chart1", 0, 1);
    chartSeriesCountTest("groupFooter.chart1", 0, 3);
    chartDataTest("groupFooter.chart1", 0, categories, series, values);
    JFreeChart chart = getChart("groupFooter.chart1", 0);
    LegendItemCollection fixedLegendItems = chart.getCategoryPlot().getFixedLegendItems();
    Assert.assertEquals("series name", "series1", fixedLegendItems.get(0).getLabel());
    testMap(chart, "group1", "group2", "group3");

    series = new String[] { "group2" + GroupedStackedBarRendererCustomizer.GROUP_SERIES_KEY + "series1",
            "group4" + GroupedStackedBarRendererCustomizer.GROUP_SERIES_KEY + "series1",
            "group5" + GroupedStackedBarRendererCustomizer.GROUP_SERIES_KEY + "series1",
            "group6" + GroupedStackedBarRendererCustomizer.GROUP_SERIES_KEY + "series1" };
    values = new Number[][] { { 4d, 5d, 6d, 7d } };
    chartCategoryCountTest("groupFooter.chart1", 1, 1);
    chartSeriesCountTest("groupFooter.chart1", 1, 4);
    chartDataTest("groupFooter.chart1", 1, categories, series, values);
    chart = getChart("groupFooter.chart1", 1);
    fixedLegendItems = chart.getCategoryPlot().getFixedLegendItems();
    Assert.assertEquals("series name", "series1", fixedLegendItems.get(0).getLabel());
    testMap(chart, "group2", "group4", "group5", "group6");
}

From source file:net.sf.dynamicreports.test.jasper.chart.LayeredBarChartTest.java

@Override
public void test() {
    super.test();

    numberOfPagesTest(1);//w  w  w.  j ava  2 s  .c o  m

    JFreeChart chart = getChart("summary.chart1", 0);
    CategoryPlot categoryPlot = chart.getCategoryPlot();
    Assert.assertEquals("renderer", LayeredBarRenderer.class, categoryPlot.getRenderer().getClass());
    Assert.assertTrue("show labels", categoryPlot.getRenderer().getBaseItemLabelsVisible());
    Assert.assertFalse("show tick labels", categoryPlot.getDomainAxis().isTickMarksVisible());
    Assert.assertFalse("show tick marks", categoryPlot.getDomainAxis().isTickLabelsVisible());

    chart = getChart("summary.chart2", 0);
    Axis axis = chart.getCategoryPlot().getDomainAxis();
    Assert.assertEquals("category label", "category", axis.getLabel());
    Assert.assertEquals("category label color", Color.BLUE, axis.getLabelPaint());
    Assert.assertEquals("category label font", new Font("Arial", Font.BOLD, 10), axis.getLabelFont());
    Assert.assertEquals("tick label color", Color.CYAN, axis.getTickLabelPaint());
    Assert.assertEquals("tick label font", new Font("Arial", Font.ITALIC, 10), axis.getTickLabelFont());
    CategoryLabelPosition labelPosition = chart.getCategoryPlot().getDomainAxis().getCategoryLabelPositions()
            .getLabelPosition(RectangleEdge.LEFT);
    Assert.assertEquals("plot label rotation", (45d / 180) * Math.PI, labelPosition.getAngle());
    Assert.assertEquals("line color", Color.LIGHT_GRAY, axis.getAxisLinePaint());

    chart = getChart("summary.chart3", 0);
    axis = chart.getCategoryPlot().getRangeAxis();
    Assert.assertEquals("value label", "value", axis.getLabel());
    Assert.assertEquals("value label color", Color.BLUE, axis.getLabelPaint());
    Assert.assertEquals("value label font", new Font("Arial", Font.BOLD, 10), axis.getLabelFont());
    Assert.assertEquals("tick label color", Color.CYAN, axis.getTickLabelPaint());
    Assert.assertEquals("tick label font", new Font("Arial", Font.ITALIC, 10), axis.getTickLabelFont());
    Assert.assertEquals("tick label mask", "10.00", ((NumberAxis) axis).getNumberFormatOverride().format(10));
    Assert.assertEquals("line color", Color.LIGHT_GRAY, axis.getAxisLinePaint());
    Assert.assertEquals("range min value", 1d, ((ValueAxis) axis).getLowerBound());
    Assert.assertEquals("range max value", 15d, ((ValueAxis) axis).getUpperBound());
}