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.design.transformation.chartcustomizer.LayeredBarRendererCustomizer.java

@Override
public void customize(JFreeChart chart, ReportParameters reportParameters) {
    BarRenderer categoryRenderer = (BarRenderer) chart.getCategoryPlot().getRenderer();
    LayeredBarRenderer renderer = new LayeredBarRenderer();

    renderer.setBaseItemLabelsVisible(categoryRenderer.getBaseItemLabelsVisible());
    renderer.setBaseItemLabelFont(categoryRenderer.getBaseItemLabelFont());
    renderer.setBaseItemLabelPaint(categoryRenderer.getBaseItemLabelPaint());
    renderer.setBaseItemLabelGenerator(categoryRenderer.getBaseItemLabelGenerator());
    renderer.setShadowVisible(categoryRenderer.getShadowsVisible());
    CategoryDataset categoryDataset = chart.getCategoryPlot().getDataset();
    if (categoryDataset != null) {
        for (int i = 0; i < categoryDataset.getRowCount(); i++) {
            Paint seriesOutlinePaint = categoryRenderer.getSeriesOutlinePaint(i);
            if (seriesOutlinePaint != null) {
                renderer.setSeriesOutlinePaint(i, seriesOutlinePaint);
            }//from  w ww. ja  v a  2 s  .com
            Paint seriesPaint = categoryRenderer.getSeriesPaint(i);
            if (seriesPaint != null) {
                renderer.setSeriesPaint(i, seriesPaint);
            }
        }
    }
    renderer.setItemMargin(categoryRenderer.getItemMargin());
    GradientPaintTransformer gradientPaintTransformer = categoryRenderer.getGradientPaintTransformer();
    if (gradientPaintTransformer != null) {
        renderer.setGradientPaintTransformer(gradientPaintTransformer);
    }

    if (seriesBarWidths != null) {
        for (int i = 0; i < seriesBarWidths.size(); i++) {
            renderer.setSeriesBarWidth(i, seriesBarWidths.get(i));
        }
    }

    chart.getCategoryPlot().setRenderer(renderer);
}

From source file:net.sf.dynamicreports.design.transformation.chartcustomizer.SeriesOrderCustomizer.java

@Override
public void customize(JFreeChart chart, ReportParameters reportParameters) {
    if (chart.getPlot() instanceof CategoryPlot) {
        CategoryDataset dataset = new SeriesOrderCategoryDataset(chart.getCategoryPlot().getDataset(),
                seriesOrderBy, seriesOrderType);
        chart.getCategoryPlot().setDataset(dataset);
    }//  www  .  ja  v a 2s .  c o m
}

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

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

    numberOfPagesTest(1);//from   ww w.  jav a 2s.  c  o m

    String[] categories = new String[] { "value1" };
    String[] series = new String[] {
            "group1" + GroupedStackedBarRendererCustomizer.GROUP_SERIES_KEY + "series1",
            "group1" + GroupedStackedBarRendererCustomizer.GROUP_SERIES_KEY + "series3",
            "group1" + GroupedStackedBarRendererCustomizer.GROUP_SERIES_KEY + "series4" };
    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());
    Assert.assertEquals("series name", "series3", fixedLegendItems.get(1).getLabel());
    Assert.assertEquals("series name", "series4", fixedLegendItems.get(2).getLabel());

    series = new String[] { "group1" + GroupedStackedBarRendererCustomizer.GROUP_SERIES_KEY + "series1",
            "group1" + GroupedStackedBarRendererCustomizer.GROUP_SERIES_KEY + "series2",
            "group1" + GroupedStackedBarRendererCustomizer.GROUP_SERIES_KEY + "series3",
            "group1" + GroupedStackedBarRendererCustomizer.GROUP_SERIES_KEY + "series4" };
    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());
    Assert.assertEquals("series name", "series2", fixedLegendItems.get(1).getLabel());
    Assert.assertEquals("series name", "series3", fixedLegendItems.get(2).getLabel());
    Assert.assertEquals("series name", "series4", fixedLegendItems.get(3).getLabel());
}

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

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

    numberOfPagesTest(1);/*w ww.j a  v a  2s  . com*/

    JFreeChart chart = getChart("summary.chart1", 0);
    CategoryPlot categoryPlot = chart.getCategoryPlot();
    Assert.assertEquals("renderer", BarRenderer.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());
}

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

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

    numberOfPagesTest(1);/*from w w w.  j  a v a2s  . c om*/

    JFreeChart chart = getChart("summary.chart1", 0);
    CategoryPlot categoryPlot = chart.getCategoryPlot();
    Assert.assertEquals("renderer", StackedBarRenderer.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());
}

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

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

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

    JFreeChart chart = getChart("summary.chart1", 0);
    CategoryPlot categoryPlot = chart.getCategoryPlot();
    Assert.assertEquals("renderer", WaterfallBarRenderer.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());
}

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

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

    numberOfPagesTest(1);/*www .ja v  a 2  s . c  om*/

    JFreeChart chart = getChart("summary.chart1", 0);
    CategoryPlot categoryPlot = chart.getCategoryPlot();
    Assert.assertEquals("renderer", BarRenderer3D.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.LineChartTest.java

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

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

    JFreeChart chart = getChart("summary.chart1", 0);
    CategoryItemRenderer renderer = chart.getCategoryPlot().getRenderer();
    Assert.assertEquals("renderer", LineAndShapeRenderer.class, renderer.getClass());
    Assert.assertFalse("show shapes", ((LineAndShapeRenderer) renderer).getBaseShapesVisible());
    Assert.assertFalse("show lines", ((LineAndShapeRenderer) renderer).getBaseLinesVisible());

    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:org.apache.qpid.disttest.charting.chartbuilder.CategoryDataSetBasedChartBuilder.java

@Override
protected final JFreeChart createChartImpl(String title, String xAxisTitle, String yAxisTitle, Dataset dataset,
        PlotOrientation plotOrientation, boolean showLegend, boolean showToolTips, boolean showUrls) {
    JFreeChart chart = createCategoryChart(title, xAxisTitle, yAxisTitle, dataset, plotOrientation, showLegend,
            showToolTips, showUrls);/* w  w  w .j a  v  a2s  . co  m*/
    chart.getCategoryPlot().getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.UP_45);
    return chart;
}

From source file:net.sf.dynamicreports.design.transformation.chartcustomizer.WaterfallBarRendererCustomizer.java

@Override
public void customize(JFreeChart chart, ReportParameters reportParameters) {
    BarRenderer categoryRenderer = (BarRenderer) chart.getCategoryPlot().getRenderer();
    WaterfallBarRenderer renderer = new WaterfallBarRenderer();

    renderer.setBaseItemLabelsVisible(categoryRenderer.getBaseItemLabelsVisible());
    renderer.setBaseItemLabelFont(categoryRenderer.getBaseItemLabelFont());
    renderer.setBaseItemLabelPaint(categoryRenderer.getBaseItemLabelPaint());
    renderer.setBaseItemLabelGenerator(categoryRenderer.getBaseItemLabelGenerator());
    renderer.setShadowVisible(categoryRenderer.getShadowsVisible());
    CategoryDataset categoryDataset = chart.getCategoryPlot().getDataset();
    if (categoryDataset != null) {
        for (int i = 0; i < categoryDataset.getRowCount(); i++) {
            Paint seriesOutlinePaint = categoryRenderer.getSeriesOutlinePaint(i);
            if (seriesOutlinePaint != null) {
                renderer.setSeriesOutlinePaint(i, seriesOutlinePaint);
            }/*from  ww w  .  ja  va  2 s. co  m*/
            Paint seriesPaint = categoryRenderer.getSeriesPaint(i);
            if (seriesPaint != null) {
                renderer.setSeriesPaint(i, seriesPaint);
            }
        }
    }
    renderer.setItemMargin(categoryRenderer.getItemMargin());
    GradientPaintTransformer gradientPaintTransformer = categoryRenderer.getGradientPaintTransformer();
    if (gradientPaintTransformer != null) {
        renderer.setGradientPaintTransformer(gradientPaintTransformer);
    }

    if (firstBarPaint != null) {
        renderer.setFirstBarPaint(firstBarPaint);
    }
    if (lastBarPaint != null) {
        renderer.setLastBarPaint(lastBarPaint);
    }
    if (positiveBarPaint != null) {
        renderer.setPositiveBarPaint(positiveBarPaint);
    }
    if (negativeBarPaint != null) {
        renderer.setNegativeBarPaint(negativeBarPaint);
    }

    chart.getCategoryPlot().setRenderer(renderer);
}