Example usage for org.jfree.chart.plot XYPlot getRenderer

List of usage examples for org.jfree.chart.plot XYPlot getRenderer

Introduction

In this page you can find the example usage for org.jfree.chart.plot XYPlot getRenderer.

Prototype

public XYItemRenderer getRenderer() 

Source Link

Document

Returns the renderer for the primary dataset.

Usage

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

public void testValidateXYLineChartItemLabels() throws ResourceException, Exception {
    final URL url = getClass().getResource("Prd-4343.prpt");
    assertNotNull(url);/*from  w  w  w.  ja  va  2  s .co  m*/
    final ResourceManager resourceManager = new ResourceManager();
    resourceManager.registerDefaults();
    final Resource directly = resourceManager.createDirectly(url, MasterReport.class);
    final MasterReport report = (MasterReport) directly.getResource();

    LogicalPageBox logicalPageBox = DebugReportRunner.layoutPage(report, 0);
    final RenderNode renderNode = MatchFactory.findElementByName(logicalPageBox, "xy-chart");
    assertTrue(renderNode instanceof RenderableReplacedContentBox);

    final RenderableReplacedContentBox xyChart = (RenderableReplacedContentBox) renderNode;
    RenderableReplacedContent xyChartContent = xyChart.getContent();
    assertTrue(xyChartContent.getRawObject() instanceof DrawableWrapper);

    final DrawableWrapper drawable = (DrawableWrapper) xyChartContent.getRawObject();
    assertTrue(drawable.getBackend() instanceof JFreeChartReportDrawable);
    final JFreeChartReportDrawable jFreeChartReportDrawable = (JFreeChartReportDrawable) drawable.getBackend();
    final JFreeChart xyLineChart = jFreeChartReportDrawable.getChart();
    final XYPlot xyLinePlot = xyLineChart.getXYPlot();

    assertTrue(xyLinePlot.getRenderer() instanceof XYLineAndShapeRenderer);
    final XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) xyLinePlot.getRenderer();
    assertNotNull(renderer);
    assertTrue(renderer.getBaseLinesVisible());
    assertNotNull(renderer.getBaseItemLabelGenerator());
    assertTrue(renderer.getBaseItemLabelGenerator() instanceof StandardXYItemLabelGenerator);
}

From source file:net.sf.mzmine.chartbasics.HistogramChartFactory.java

public static JFreeChart createHistogram(XYSeries series, double barwidth, String yAxisLabel) {
    XYSeriesCollection xydata = new XYSeriesCollection(series);
    XYBarDataset dataset = new XYBarDataset(xydata, barwidth);
    JFreeChart chart = ChartFactory.createXYBarChart("", yAxisLabel, false, "n", dataset,
            PlotOrientation.VERTICAL, true, true, false);

    XYPlot xyplot = chart.getXYPlot();
    chart.setBackgroundPaint(new Color(230, 230, 230));
    chart.getLegend().setVisible(false);
    xyplot.setForegroundAlpha(0.7F);/*w  w  w  . j  av a2 s. com*/
    xyplot.setBackgroundPaint(Color.WHITE);
    xyplot.setDomainGridlinePaint(new Color(150, 150, 150));
    xyplot.setRangeGridlinePaint(new Color(150, 150, 150));
    xyplot.getDomainAxis().setVisible(true);
    xyplot.getRangeAxis().setVisible(yAxisLabel != null);
    XYBarRenderer xybarrenderer = (XYBarRenderer) xyplot.getRenderer();
    xybarrenderer.setShadowVisible(false);
    xybarrenderer.setBarPainter(new StandardXYBarPainter());
    xybarrenderer.setDrawBarOutline(false);
    return chart;
}

From source file:ec.util.chart.swing.Charts.java

/**
 * A sparkline is a type of information graphic characterized by its small
 * size and high data density. Sparklines present trends and variations
 * associated with some measurement, such as average temperature or stock
 * market activity, in a simple and condensed way. Several sparklines are
 * often used together as elements of a small multiple.<br>
 *
 * {@link http://en.wikipedia.org/wiki/Sparkline}
 *
 * @param dataset//from   w  ww.j  a v  a 2 s.c om
 * @return
 * @author Philippe Charles
 */
@Nonnull
public static JFreeChart createSparkLineChart(@Nonnull XYDataset dataset) {
    JFreeChart result = ChartFactory.createTimeSeriesChart(null, null, null, dataset, false, false, false);
    result.setBorderVisible(false);
    result.setBackgroundPaint(null);
    result.setAntiAlias(true);
    XYPlot plot = result.getXYPlot();
    plot.getRangeAxis().setVisible(false);
    plot.getDomainAxis().setVisible(false);
    plot.setDomainGridlinesVisible(false);
    plot.setDomainCrosshairVisible(false);
    plot.setRangeGridlinesVisible(false);
    plot.setRangeCrosshairVisible(false);
    plot.setOutlineVisible(false);
    plot.setInsets(RectangleInsets.ZERO_INSETS);
    plot.setAxisOffset(RectangleInsets.ZERO_INSETS);
    plot.setBackgroundPaint(null);
    ((XYLineAndShapeRenderer) plot.getRenderer()).setAutoPopulateSeriesPaint(false);
    return result;
}

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

protected void configureChart(final JFreeChart chart) {
    super.configureChart(chart);

    final XYPlot xypl = chart.getXYPlot();
    final XYItemRenderer renderer = xypl.getRenderer();
    if (renderer instanceof XYDotRenderer) {
        final XYDotRenderer renderer1 = (XYDotRenderer) renderer;
        renderer1.setDotHeight(getDotHeight());
        renderer1.setDotWidth(getDotWidth());
    }/*from www. ja va  2s .com*/

}

From source file:com.alcatel_lucent.nz.wnmsreport.chart.TimeSeriesIuRChartCustomiser.java

public void customise(JFreeChart chart, JRChart jasperchart) {
    XYPlot xyplot = chart.getXYPlot();
    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) xyplot.getRenderer();
    XYDataset xyDataset = xyplot.getDataset();
    LegendItemCollection legend = xyplot.getLegendItems();
    LegendItemCollection revised = new LegendItemCollection();

    if (xyDataset != null) {
        for (int i = 0; i < xyDataset.getSeriesCount(); i++) {
            if (i < 1) {
                //make line 1 dashed
                renderer.setSeriesStroke(i, stroke_dashed);
            } else {
                //make other lines filled and add to new legend
                renderer.setSeriesStroke(i, stroke_normal);
                revised.add(legend.get(i));
            }//  w w w .  ja  v  a 2s .com
            renderer.setSeriesLinesVisible(i, true);
        }
    }
    xyplot.setFixedLegendItems(revised);
}

From source file:org.nbrcp.demo.core.views.Scatterplot.java

private void setUpView() {
    JFreeChart chart = ChartFactory.createScatterPlot("", "X", "Y", Data.getDataset());
    XYPlot plot = (XYPlot) chart.getPlot();
    Shape dotShape = new Ellipse2D.Double(0, 0, 5, 5);
    XYItemRenderer renderer = plot.getRenderer();
    renderer.setSeriesShape(0, dotShape);

    final ChartPanel panel = new ChartPanel(chart, true);
    panel.setMinimumDrawHeight(10);// w w  w .j  a v a2  s.  c o m
    panel.setMaximumDrawHeight(2000);
    panel.setMinimumDrawWidth(10);
    panel.setMaximumDrawWidth(2000);
    panel.setSize(this.getSize());
    this.add(panel);
}

From source file:com.continuent.bristlecone.evaluator.MovingAverageDemo.java

/**
 * A moving average demo.// www  .j a va  2s  . c  o  m
 *
 * @param title  the frame title.
 */
public MovingAverageDemo(String title) {

    super(title);

    // create a title...
    String chartTitle = "Legal & General Unit Trust Prices";
    XYDataset dataset = createDataset();

    JFreeChart chart = ChartFactory.createTimeSeriesChart(chartTitle, "Date", "Price Per Unit", dataset, true,
            true, false);

    XYPlot plot = (XYPlot) chart.getPlot();
    XYItemRenderer renderer = plot.getRenderer();
    if (renderer instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer rr = (XYLineAndShapeRenderer) renderer;
        rr.setBaseShapesVisible(true);
        rr.setBaseShapesFilled(true);
    }
    DateAxis axis = (DateAxis) plot.getDomainAxis();
    //axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy"));
    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    setContentPane(chartPanel);

}

From source file:net.sf.jasperreports.customizers.shape.LegendShapeCustomizer.java

@Override
public void customize(JFreeChart jfc, JRChart jrc) {
    Plot plot = jfc.getPlot();/*w w w  . j a  v  a 2s  .com*/

    ItemsCounter itemsCounter = new LegendItemsCounter(plot);
    SeriesNameProvider seriesNameProvider = null;
    Object renderer = null;

    if (plot instanceof XYPlot) {
        XYPlot xyPlot = jfc.getXYPlot();
        renderer = xyPlot.getRenderer();
        seriesNameProvider = new XYPlotSeriesNameProvider(xyPlot);
    } else if (plot instanceof CategoryPlot) {
        CategoryPlot categoryPlot = jfc.getCategoryPlot();
        renderer = categoryPlot.getRenderer();
        seriesNameProvider = new CategorySeriesNameProvider(categoryPlot);
    }

    Integer legendItemIndex = CustomizerUtil.resolveIndex(this, itemsCounter, seriesNameProvider);
    if (legendItemIndex != null && renderer instanceof AbstractRenderer) {
        ShapeSetter shapeSetter = new AbstractRendererLegendShapeSetter((AbstractRenderer) renderer);
        if (legendItemIndex == -1) {
            updateItems(itemsCounter, shapeSetter);
        } else {
            updateItem(itemsCounter, shapeSetter, legendItemIndex);
        }
    }
}

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

protected void configureChart(final JFreeChart chart) {
    super.configureChart(chart);

    final XYPlot xypl = chart.getXYPlot();
    final XYItemRenderer renderer = xypl.getRenderer();
    renderer.setStroke(translateLineStyle(lineWidth, lineStyle));
    if (renderer instanceof XYLineAndShapeRenderer) {
        final XYLineAndShapeRenderer renderer1 = (XYLineAndShapeRenderer) renderer;
        renderer1.setShapesVisible(isMarkersVisible());
        renderer1.setBaseShapesFilled(isMarkersVisible());
    }/*from  w ww  . j av a2s.  c  om*/

}

From source file:clonalgtcc.PlotTest.java

private JFreeChart createChart(final XYDataset dataset) {
    final JFreeChart chart = ChartFactory.createScatterPlot("Ruspini", // chart title
            "X", // x axis label
            "Y", // y axis label
            dataset, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips
            false // urls
    );/*from   w w  w.  j av a2 s . c  o  m*/
    XYPlot xyPlot = chart.getXYPlot();
    XYItemRenderer renderer = xyPlot.getRenderer();

    //        renderer.setSeriesPaint( 4, Color.BLUE );
    //        renderer.setSeriesShape(1, new Ellipse2D.Double(-3, -3, 6, 6));
    //        renderer.setSeriesShape(2, new Ellipse2D.Double(-3, -3, 6, 6));
    //        renderer.setSeriesShape(3, new Ellipse2D.Double(-3, -3, 6, 6));
    //        renderer.setSeriesShape(4, new Ellipse2D.Double(-3, -3, 6, 6));

    // Comentando essas linhas abaixo;
    //        XYPlot plot = (XYPlot) chart.getPlot();
    //        XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    //        renderer.setSeriesLinesVisible(0, true);
    //        plot.setRenderer(renderer);
    // At aqui
    return chart;
}