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

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

Introduction

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

Prototype

public void setRenderer(XYItemRenderer renderer) 

Source Link

Document

Sets the renderer for the primary dataset and sends a change event to all registered listeners.

Usage

From source file:org.jfree.chart.demo.XYBarChartDemo2.java

/** 
 * Creates a chart.//from w w w  .j  ava  2s . com
 * 
 * @param dataset  the dataset.
 * 
 * @return The chart.
 */
private JFreeChart createChart(final IntervalXYDataset dataset) {
    final JFreeChart chart = ChartFactory.createXYBarChart("XY Bar Chart Demo 2", // chart title
            "Date", // domain axis label
            true, "Y", // range axis label
            dataset, // data
            PlotOrientation.HORIZONTAL, true, // include legend
            true, false);

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    final XYPlot plot = chart.getXYPlot();
    plot.setRenderer(new ClusteredXYBarRenderer());
    // OPTIONAL CUSTOMISATION COMPLETED.
    return chart;
}

From source file:controller.DrawCurve.java

private JPanel createChart() {
    String chartTitle = "Camera Response Curve";
    String xAxisLabel = "log Exposure G(Z)";
    String yAxisLabel = "Intensity pixel Z";

    XYDataset dataset = createDataset();

    JFreeChart chart = ChartFactory.createXYLineChart(chartTitle, xAxisLabel, yAxisLabel, dataset);

    //Set custom color and thickness for line curve
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false);

    // sets paint color for each series
    renderer.setSeriesPaint(0, Color.RED);
    renderer.setSeriesPaint(1, Color.GREEN);
    renderer.setSeriesPaint(2, Color.BLUE);

    // sets thickness for series (using strokes)
    renderer.setSeriesStroke(0, new BasicStroke(1.5f));
    renderer.setSeriesStroke(1, new BasicStroke(1.5f));
    renderer.setSeriesStroke(2, new BasicStroke(1.5f));

    XYPlot plot = chart.getXYPlot();
    plot.setRenderer(renderer);

    return new ChartPanel(chart);
}

From source file:org.jfree.chart.demo.DifferenceChartDemo.java

/**
 * Creates a chart./*from www  .  j a v  a 2 s. com*/
 * 
 * @param dataset  the dataset.
 * 
 * @return The chart.
 */
private JFreeChart createChart(final XYDataset dataset) {
    final JFreeChart chart = ChartFactory.createTimeSeriesChart("Difference Chart Demo", "Time", "Value",
            dataset, true, // legend
            true, // tool tips
            false // URLs
    );
    chart.setBackgroundPaint(Color.white);

    final XYPlot plot = chart.getXYPlot();
    plot.setRenderer(new XYDifferenceRenderer(Color.green, Color.red, false));
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    //        plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));

    final ValueAxis domainAxis = new DateAxis("Time");
    domainAxis.setLowerMargin(0.0);
    domainAxis.setUpperMargin(0.0);
    plot.setDomainAxis(domainAxis);
    plot.setForegroundAlpha(0.5f);
    return chart;
}

From source file:org.jfree.chart.demo.ChartTiming3.java

/**
 * Runs the test.//from  w  ww .ja v  a 2  s  .  co m
 */
public void run() {

    this.finished = false;

    // create a dataset...
    final XYSeries series = new XYSeries("Random Data");
    for (int i = 0; i < 1440; i++) {
        final double x = Math.random();
        final double y = Math.random();
        series.add(x, y);
    }
    final XYDataset data = new XYSeriesCollection(series);

    // create a scatter chart...
    final boolean withLegend = true;
    final JFreeChart chart = ChartFactory.createScatterPlot("Scatter plot timing", "X", "Y", data,
            PlotOrientation.VERTICAL, withLegend, false, false);

    final XYPlot plot = chart.getXYPlot();
    plot.setRenderer(new XYDotRenderer());

    final BufferedImage image = new BufferedImage(400, 300, BufferedImage.TYPE_INT_RGB);
    final Graphics2D g2 = image.createGraphics();
    final Rectangle2D chartArea = new Rectangle2D.Double(0, 0, 400, 300);

    // set up the timer...
    final Timer timer = new Timer(10000, this);
    timer.setRepeats(false);
    int count = 0;
    timer.start();
    while (!this.finished) {
        chart.draw(g2, chartArea, null, null);
        System.out.println("Charts drawn..." + count);
        if (!this.finished) {
            count++;
        }
    }
    System.out.println("DONE");

}

From source file:uk.ac.ed.epcc.webapp.charts.jfreechart.JFreeScatterPeriodChartData.java

@Override
public JFreeChart getJFreeChart() {
    if (chart == null) {
        chart = ChartFactory.createScatterPlot(title, xaxis, yaxis, coll, PlotOrientation.VERTICAL, false,
                false, false);//from  w ww.  j  a  v a2s.  c o  m
        XYDotRenderer render = new XYDotRenderer();
        render.setDotHeight(2);
        render.setDotWidth(2);
        XYPlot plot = (XYPlot) chart.getPlot();
        plot.setRenderer(render);
    }
    return chart;
}

From source file:org.hxzon.demo.jfreechart.OtherDatasetDemo.java

private static JFreeChart createBubbleChart(XYZDataset dataset) {
    NumberAxis xAxis = new NumberAxis(xAxisLabel);
    xAxis.setAutoRangeIncludesZero(false);
    NumberAxis yAxis = new NumberAxis(yAxisLabel);
    yAxis.setAutoRangeIncludesZero(false);

    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, null);
    //        A renderer that draws a circle at each data point with a diameter that is
    //        determined by the z-value in the dataset (the renderer requires the dataset
    //        to be an instance of {@link XYZDataset}.
    XYItemRenderer renderer = new XYBubbleRenderer(XYBubbleRenderer.SCALE_ON_RANGE_AXIS);
    if (tooltips) {
        renderer.setBaseToolTipGenerator(new StandardXYZToolTipGenerator());
    }//from w w w.  j a v  a 2 s.c  o  m
    if (urls) {
        renderer.setURLGenerator(new StandardXYZURLGenerator());
    }
    plot.setRenderer(renderer);
    plot.setOrientation(orientation);

    JFreeChart chart = new JFreeChart("Bubble Chart Demo", JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
    chart.setBackgroundPaint(Color.white);

    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    return chart;
}

From source file:it.unibo.alchemist.boundary.gui.asmc.SimplePlot.java

@Override
public void batchDone(final double[][] values, final double lower, final double upper, final int sampleSize) {
    this.removeAll();
    final YIntervalSeries series = new YIntervalSeries("Probability of condition satisfaction vs. time");
    for (final double[] value : values) {
        series.add(value[0], value[1], value[2], value[TRE]);
    }/*w ww  .j  av  a2s.co  m*/
    final YIntervalSeriesCollection data = new YIntervalSeriesCollection();
    data.addSeries(series);
    final JFreeChart chart = ChartFactory.createXYLineChart("", "X", "Y", data, PlotOrientation.VERTICAL, true,
            true, false);
    XYItemRenderer renderer;
    switch (currentRenderer) {
    case 1:
        renderer = new YIntervalRenderer();
        break;
    case 0:
    default:
        renderer = new DeviationRenderer(true, false);
    }
    final XYPlot plot = (XYPlot) chart.getPlot();
    plot.setRenderer(renderer);
    plot.getDomainAxis().setLowerBound(lower);
    plot.getDomainAxis().setUpperBound(upper);
    plot.getRangeAxis().setUpperBound(1.0);
    plot.getRangeAxis().setLowerBound(0.0);

    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(DIMENSION);
    this.setLayout(new BorderLayout());
    this.add(chartPanel, BorderLayout.NORTH);
    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            chartPanel.getRootPane().validate();
        }
    });
}

From source file:org.audiveris.omr.util.ChartPlotter.java

/**
 * Creates a new {@code ChartPlotter} object.
 *
 * @param title  chart title/*from   www  . j  av a 2s.co m*/
 * @param xLabel x-axis label
 * @param yLabel y-axis label
 */
public ChartPlotter(String title, String xLabel, String yLabel) {
    chart = ChartFactory.createXYLineChart(title, xLabel, yLabel, dataset, PlotOrientation.VERTICAL, true, // Show legend
            false, // Show tool tips
            false // urls
    );

    final XYPlot plot = (XYPlot) chart.getPlot();
    plot.setRenderer(renderer);
}

From source file:FreeMemoryViewer.java

private JFreeChart createChart(XYDataset dataset, String title) {
    JFreeChart chart = ChartFactory.createXYLineChart(title, "X", "Y", dataset, PlotOrientation.VERTICAL, true,
            true, false);/*from   ww  w  .j  a  v  a2s  . c o  m*/
    XYPlot plot = chart.getXYPlot();
    XYSplineRenderer renderer = new XYSplineRenderer(); // Curve
    plot.setRenderer(renderer);
    return chart;
}

From source file:edu.ucla.stat.SOCR.chart.demo.XYBarChartDemo1.java

protected JFreeChart createChart(IntervalXYDataset dataset) {
    JFreeChart chart = ChartFactory.createXYBarChart(chartTitle, domainLabel, true, rangeLabel, dataset,
            PlotOrientation.VERTICAL, !legendPanelOn, true, false);

    // then customise it a little...
    // chart.addSubtitle(new TextTitle("Source: http://www.amnestyusa.org/abolish/listbyyear.do"));
    chart.setBackgroundPaint(Color.white);

    XYPlot plot = chart.getXYPlot();
    plot.setRenderer(new ClusteredXYBarRenderer());
    XYItemRenderer renderer = plot.getRenderer();

    StandardXYToolTipGenerator generator = new StandardXYToolTipGenerator("{1} = {2}",
            new SimpleDateFormat("yyyy"), new DecimalFormat("0"));
    renderer.setBaseToolTipGenerator(generator);
    renderer.setLegendItemLabelGenerator(new SOCRXYSeriesLabelGenerator());

    plot.setBackgroundPaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.white);

    DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setTickMarkPosition(DateTickMarkPosition.MIDDLE);
    axis.setLowerMargin(0.01);//  w  ww  .  ja  v a  2s .  c  o  m
    axis.setUpperMargin(0.01);
    //      setXSummary(dataset);  X  is time
    return chart;
}