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:edu.ucla.stat.SOCR.chart.demo.XYBarChartDemo2.java

/** 
 * Creates a chart./*from   ww  w .  ja  va2s.c om*/
 * 
 * @param dataset  the dataset.
 * 
 * @return The chart.
 */
protected JFreeChart createChart(IntervalXYDataset dataset) {
    JFreeChart chart = ChartFactory.createXYBarChart(chartTitle, // chart title
            domainLabel, // domain axis label
            true, rangeLabel, // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, !legendPanelOn, // include legend
            //false,   // when choose no legend, the color order used in chart is different 
            true, false);

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

    XYItemRenderer renderer = plot.getRenderer();
    renderer.setBaseToolTipGenerator(
            new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT,
                    new SimpleDateFormat("d-MMM-yy"), new DecimalFormat("#,##0.00")));
    renderer.setLegendItemLabelGenerator(new SOCRXYSeriesLabelGenerator());
    // OPTIONAL CUSTOMISATION COMPLETED.

    //setXSummary(dataset);  X is time
    return chart;
}

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

protected JFreeChart createLegend(IntervalXYDataset dataset) {

    JFreeChart chart = ChartFactory.createXYBarChart(chartTitle, // chart title
            domainLabel, // domain axis label
            true, rangeLabel, // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, false);//from w w  w .  ja  v a  2 s  . c  o  m

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

    XYItemRenderer renderer = plot.getRenderer();
    renderer.setBaseToolTipGenerator(
            new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT,
                    new SimpleDateFormat("d-MMM-yy"), new DecimalFormat("#,##0.00")));
    renderer.setLegendItemLabelGenerator(new SOCRXYSeriesLabelGenerator());
    // OPTIONAL CUSTOMISATION COMPLETED.

    //setXSummary(dataset);  X is time
    return chart;

}

From source file:org.uncommons.maths.demo.GraphPanel.java

public void generateGraph(String title, Map<Double, Double> observedValues, Map<Double, Double> expectedValues,
        double expectedMean, double expectedStandardDeviation, boolean discrete) {
    XYSeriesCollection dataSet = new XYSeriesCollection();
    XYSeries observedSeries = new XYSeries("Observed");
    dataSet.addSeries(observedSeries);/*from  w w w.j  a  v  a 2 s  .  c o  m*/
    XYSeries expectedSeries = new XYSeries("Expected");
    dataSet.addSeries(expectedSeries);

    for (Map.Entry<Double, Double> entry : observedValues.entrySet()) {
        observedSeries.add(entry.getKey(), entry.getValue());
    }

    for (Map.Entry<Double, Double> entry : expectedValues.entrySet()) {
        expectedSeries.add(entry.getKey(), entry.getValue());
    }

    JFreeChart chart = ChartFactory.createXYLineChart(title, "Value", "Probability", dataSet,
            PlotOrientation.VERTICAL, true, false, false);
    XYPlot plot = (XYPlot) chart.getPlot();
    if (discrete) {
        // Render markers at each data point (these discrete points are the
        // distibution, not the lines between them).
        plot.setRenderer(new XYLineAndShapeRenderer());
    } else {
        // Render smooth lines between points for a continuous distribution.
        XYSplineRenderer renderer = new XYSplineRenderer();
        renderer.setBaseShapesVisible(false);
        plot.setRenderer(renderer);
    }

    chartPanel.setChart(chart);
}

From source file:ste.travian.world.WorldChart.java

/**
 * Create the JFreeChart world chart/*from  w w  w .  ja  v a2s  .  c o m*/
 * 
 * @param title world title
 * @param dataset world data set
 * 
 */
private void createWorldPlot(String title, XYDataset dataset) {

    NumberAxis xAxis = new NumberAxis(LABEL_X_AXIS);
    xAxis.setAutoRangeIncludesZero(false);
    NumberAxis yAxis = new NumberAxis(LABEL_Y_AXIS);
    yAxis.setAutoRangeIncludesZero(false);

    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, null);

    TileRenderer renderer = new TileRenderer(3, 3);
    renderer.setBaseToolTipGenerator(new TileToolTipGenerator());

    plot.setRenderer(renderer);
    plot.setOrientation(PlotOrientation.VERTICAL);

    chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, true);
}

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

/**
 * A demonstration application./*from   w  ww.  jav a  2s.  co  m*/
 * 
 * @param title
 *           the frame title.
 */
public SymbolicChartDemo1(final String title) {

    super(title);

    // create a title...
    final XYDataset dataset = createDataset();

    final ValueAxis domainAxis = new NumberAxis("X");
    final SymbolicAxis symbolicAxis = new SymbolicAxis("Y", ((YisSymbolic) dataset).getYSymbolicValues());

    final XYPlot plot = new XYPlot(dataset, domainAxis, symbolicAxis, null);
    final XYItemRenderer renderer = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES,
            new SymbolicXYItemLabelGenerator());
    plot.setRenderer(renderer);
    final JFreeChart chart = new JFreeChart(title, plot);

    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    setContentPane(chartPanel);

}

From source file:tp2.FCFS.java

@Override
public void printGraph(String filename) {
    int i;//w w  w .  ja v a 2s.  co m
    int y_axis = requestString.length * 10;

    XYSeries series = new XYSeries("FCFS");

    /* Adiciona o pontos XY do grfico de linhas. */
    series.add(y_axis, initCilindro);

    for (i = 0; i < requestString.length; i++) {
        series.add(y_axis - ((i + 1) * 10), requestString[i]);
    }

    /* Adiciona a serie criada a um SeriesCollection. */
    XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.addSeries(series);

    /* Gera o grfico de linhas */
    JFreeChart chart = ChartFactory.createXYLineChart(
            /* Title */
            "FCFS Scheduler Algorithm",
            /* Title x*/
            "",
            /* Title y */
            "Cilindro", dataset,
            /* Plot Orientation */
            PlotOrientation.HORIZONTAL,
            /* Show Legend */
            false,
            /* Use tooltips */
            false,
            /* Configure chart to generate URLs? */
            false);

    /* Configura a espessura da linha do grfico  */
    XYPlot plot = chart.getXYPlot();

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesStroke(0, new BasicStroke(4.0f));
    plot.setRenderer(renderer);

    /* Escreve o grfico para um arquivo indicado. */
    try {
        ChartUtilities.saveChartAsJPEG(new File(filename), chart, 500, 300);
    } catch (IOException ex) {
        Logger.getLogger(FCFS.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:playground.dgrether.analysis.charts.DgDeltaUtilsModeGroupChart.java

/**
 * @see playground.dgrether.analysis.charts.interfaces.DgChart#createChart()
 *///from w  w  w.  j ava 2s.c  o  m
@Override
public JFreeChart createChart() {
    XYPlot plot = new XYPlot(this.dataset, new NumberAxis("Income"), new NumberAxis("Delta utils"), null);
    XYItemRenderer renderer = new XYLineAndShapeRenderer(false, true);
    plot.setRenderer(renderer);

    JFreeChart jchart = new JFreeChart("", plot);
    return jchart;
}

From source file:playground.benjamin.scenarios.zurich.analysis.charts.BkDeltaUtilsChart.java

public JFreeChart createChart() {
    XYPlot plot = new XYPlot(this.dataset, new NumberAxis("individual income"), new NumberAxis("delta utils"),
            null);//from ww  w  .j av a 2 s .  c om
    XYItemRenderer renderer = new XYLineAndShapeRenderer(false, true);
    plot.setRenderer(renderer);

    JFreeChart jchart = new JFreeChart("", plot);
    return jchart;
}

From source file:playground.benjamin.scenarios.zurich.analysis.charts.BkDeltaUtilsQuantilesChart.java

public JFreeChart createChart() {
    XYPlot plot = new XYPlot(this.dataset, new NumberAxis("population deciles sorted by income"),
            new NumberAxis("delta utils"), null);
    XYItemRenderer renderer = new XYLineAndShapeRenderer(false, true);
    plot.setRenderer(renderer);

    JFreeChart jchart = new JFreeChart("", plot);
    return jchart;
}

From source file:org.matsim.contrib.parking.parkingchoice.lib.GeneralLib.java

public static void generateXYScatterPlot(String fileName, double[] x, double[] y, String title, String xLabel,
        String yLabel) {/*  ww  w . ja v a  2 s .c  o m*/

    if (x.length != y.length) {
        DebugLib.stopSystemAndReportInconsistency("dimensions of arrays do not match");
    }

    final XYSeries series1 = new XYSeries(title);

    for (int i = 0; i < x.length; i++) {
        series1.add(x[i], y[i]);
    }

    final XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.addSeries(series1);

    final JFreeChart chart = ChartFactory.createXYLineChart(title, xLabel, yLabel, dataset,
            PlotOrientation.VERTICAL, true, true, false);

    chart.setBackgroundPaint(Color.white);

    final XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesLinesVisible(0, false);
    renderer.setSeriesShapesVisible(1, false);
    plot.setRenderer(renderer);

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

    int width = 500;
    int height = 300;

    try {
        ChartUtilities.saveChartAsPNG(new File(fileName), chart, width, height);
    } catch (IOException e) {

    }
}