Example usage for org.jfree.chart.renderer.category CategoryItemRenderer getClass

List of usage examples for org.jfree.chart.renderer.category CategoryItemRenderer getClass

Introduction

In this page you can find the example usage for org.jfree.chart.renderer.category CategoryItemRenderer getClass.

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

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

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

    numberOfPagesTest(1);// w w w .j  a  va2s  . c om

    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:nl.strohalm.cyclos.controls.reports.statistics.graphs.ChartPostProcessorImpl.java

/**
 * This is the basic and only method which is called from the jsp. Any distinctions on what to process must be made inside this method, according
 * to params values./*w w w.jav  a2 s .co m*/
 * 
 * @param chart the chart from which it is called
 * @param params a Map with any optional params which can be called from the jsp. Params in the jsp must be passed according to the following
 * example:
 * 
 * <pre>
 * &lt;cewolf:chartpostprocessor id=&quot;chartPostProcessorImpl&quot;&gt;
 *     &lt;cewolf:param name=&quot;subtitle&quot; value=&quot;this is a subtitle&quot;/&gt;
 * &lt;/cewolf:chartpostprocessor&gt;
 * </pre>
 */
@Override
@SuppressWarnings("rawtypes")
public void processChart(final Object chart, final Map params) {
    // general method calls for all chart types
    setSubTitle(chart, params);
    setTitleFont(chart);
    // calls specific to chart types
    if (((JFreeChart) chart).getPlot().getClass() == CategoryPlot.class) {
        // GRAPH and BAR charts
        final CategoryPlot plot = (CategoryPlot) ((JFreeChart) chart).getPlot();
        setMarkers(plot, params);
        final CategoryItemRenderer renderer = plot.getRenderer();
        setRotatedXaxisLabels(plot, params);
        // Bar-specific methods
        if (renderer.getClass() == BarRenderer.class) {
            setErrorBars(plot);
            setBarColors(plot, colorRange);
            setMargins(plot);
        }
        // line-specific methods
        if (renderer.getClass() == LineAndShapeRenderer.class) {
            setLineAndShapesAndErrorBars(plot);
        }
        if (renderer.getClass() == StackedAreaRenderer.class) {
            applyStackedAreaRendering(plot);
        }
    } else {
        // PIE charts
        final PiePlot plot = (PiePlot) ((JFreeChart) chart).getPlot();
        setPieColors(plot, colorRange);
        setPieLabels(plot);
    }
}

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

@Override
public void customize(JFreeChart chart, ReportParameters reportParameters) {
    if (chart.getPlot() instanceof CategoryPlot) {
        CategoryItemRenderer renderer = chart.getCategoryPlot().getRenderer();
        if (StringUtils.isBlank(valuePattern)) {
            renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
        } else {/*from   w ww. j a  va2s.  com*/
            renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator(
                    StandardCategoryItemLabelGenerator.DEFAULT_LABEL_FORMAT_STRING,
                    new DecimalFormat(valuePattern)));
        }
        renderer.setBaseItemLabelsVisible(Boolean.TRUE);
        chart.getCategoryPlot().getRangeAxis().zoomRange(0, 1.1);
        if (renderer.getClass().equals(BarRenderer3D.class)) {
            ((BarRenderer3D) renderer).setItemLabelAnchorOffset(10D);
            renderer.setBasePositiveItemLabelPosition(
                    new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT));
        }
    } else if (chart.getPlot() instanceof XYPlot) {
        XYItemRenderer renderer = chart.getXYPlot().getRenderer();
        if (StringUtils.isBlank(valuePattern)) {
            renderer.setBaseItemLabelGenerator(new StandardXYItemLabelGenerator());
        } else {
            renderer.setBaseItemLabelGenerator(
                    new StandardXYItemLabelGenerator(StandardXYItemLabelGenerator.DEFAULT_ITEM_LABEL_FORMAT,
                            NumberFormat.getNumberInstance(), new DecimalFormat(valuePattern)));
        }
        renderer.setBaseItemLabelsVisible(Boolean.TRUE);
        chart.getXYPlot().getRangeAxis().zoomRange(0, 1.1);
    }
}