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(int index, XYItemRenderer renderer) 

Source Link

Document

Sets the renderer for the dataset with the specified index and sends a change event to all registered listeners.

Usage

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

public JFreeChart createChart() {
    XYPlot plot = new XYPlot();
    ValueAxis xAxis = this.axisBuilder.createValueAxis("% of Population Sorted by Income");
    ValueAxis yAxis = this.axisBuilder.createValueAxis("Delta Utils [Utils]");
    plot.setDomainAxis(xAxis);//from ww  w  .  ja va  2  s .co  m
    plot.setRangeAxis(yAxis);
    //RANGE
    xAxis.setRange(0.0, 102.0);
    yAxis.setRange(-0.31, 0.61);

    DgColorScheme colorScheme = new DgColorScheme();

    XYItemRenderer renderer1 = new XYLineAndShapeRenderer(false, true);
    renderer1.setSeriesPaint(0, colorScheme.COLOR1B);
    renderer1.setSeriesPaint(1, colorScheme.COLOR2B);
    renderer1.setSeriesPaint(2, colorScheme.COLOR3B);
    renderer1.setSeriesPaint(3, colorScheme.COLOR4B);
    plot.setDataset(0, this.inomeModeChoiceDs);
    plot.setRenderer(0, renderer1);

    XYItemRenderer renderer2;
    renderer2 = new XYLineAndShapeRenderer(true, true);
    plot.setDataset(1, this.avgDeltaScoreIncomeDs);
    for (int i = 0; i <= 3; i++) {
        renderer2.setSeriesStroke(i, new BasicStroke(2.0f));
        renderer2.setSeriesOutlineStroke(i, new BasicStroke(3.0f));
        renderer2.setSeriesPaint(i, colorScheme.getColor(i + 1, "a"));
    }
    plot.setRenderer(1, renderer2);
    JFreeChart chart = new JFreeChart("", plot);
    chart.setBackgroundPaint(ChartColor.WHITE);
    chart.getLegend().setItemFont(this.axisBuilder.getAxisFont());
    chart.setTextAntiAlias(true);
    return chart;
}

From source file:org.encog.workbench.dialogs.training.ChartPane.java

/**
 * Create the initial chart./*from  ww  w.  ja  va 2s .c  o m*/
 * @return The chart.
 */
private JFreeChart createChart() {

    this.chart = ChartFactory.createXYLineChart(null, "Iteration", "Current Error", this.dataset1,
            PlotOrientation.VERTICAL, true, true, false);

    final XYPlot plot = (XYPlot) this.chart.getPlot();
    plot.setOrientation(PlotOrientation.VERTICAL);

    plot.getRangeAxis().setFixedDimension(15.0);

    // AXIS 2
    final NumberAxis axis2 = new NumberAxis("Error Improvement");
    axis2.setFixedDimension(10.0);
    axis2.setAutoRangeIncludesZero(false);
    axis2.setLabelPaint(Color.red);
    axis2.setTickLabelPaint(Color.red);
    plot.setRangeAxis(1, axis2);
    plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT);

    plot.setDataset(1, this.dataset2);
    plot.mapDatasetToRangeAxis(1, 1);
    final XYItemRenderer renderer2 = new StandardXYItemRenderer();
    renderer2.setSeriesPaint(0, Color.red);
    plot.setRenderer(1, renderer2);

    ChartUtilities.applyCurrentTheme(this.chart);

    return this.chart;
}

From source file:ec.ui.view.RevisionSaSeriesView.java

private void showResults() {
    if (history_ == null) {
        return;// w w  w.j a  v a  2 s. co  m
    }

    lastIndexSelected = -1;

    final TimeSeriesCollection chartSeries = new TimeSeriesCollection();
    sRef = history_.referenceSeries(info_);
    TsPeriodSelector selector = new TsPeriodSelector();
    int n = sRef.getDomain().getLength();
    int freq = sRef.getDomain().getFrequency().intValue();
    int l = years_ * freq + 1;
    int n0 = n - l;
    if (n0 < minyears_ * freq) {
        n0 = minyears_ * freq;
    }
    if (n0 < n) {
        firstPeriod = sRef.getDomain().get(n0);
        selector.from(sRef.getDomain().get(n0).firstday());
    } else {
        firstPeriod = sRef.getStart();
    }
    addSeries(chartSeries, sRef.select(selector));

    final TimeSeriesCollection startSeries = new TimeSeriesCollection();
    TsDomain dom = sRef.getDomain();
    for (int i = n0; i < n - 1; ++i) {
        addStart(startSeries, info_, dom.get(i));
    }

    if (startSeries.getSeriesCount() == 0 || chartSeries.getSeriesCount() == 0) {
        chartpanel_.setChart(mainChart);
        return;
    }

    setRange(chartSeries, startSeries);

    XYPlot plot = mainChart.getXYPlot();
    plot.setDataset(S_INDEX, chartSeries);

    plot.setDataset(REV_INDEX, startSeries);

    for (int i = 0; i < startSeries.getSeriesCount(); i++) {
        revRenderer.setSeriesShape(i, new Ellipse2D.Double(-3, -3, 6, 6));
        revRenderer.setSeriesShapesFilled(i, false);
        revRenderer.setSeriesPaint(i, themeSupport.getLineColor(ColorScheme.KnownColor.BLUE));
    }
    plot.setRenderer(REV_INDEX, revRenderer);

    setRange(chartSeries, startSeries);
    configureAxis(plot);

    plot.mapDatasetToDomainAxis(S_INDEX, REV_INDEX);
    plot.mapDatasetToRangeAxis(S_INDEX, REV_INDEX);
    plot.mapDatasetToDomainAxis(REV_INDEX, REV_INDEX);
    plot.mapDatasetToRangeAxis(REV_INDEX, REV_INDEX);

    chartpanel_.setChart(mainChart);

    showRevisionsDocument(revisions());
}

From source file:osh.comdriver.simulation.cruisecontrol.AbstractDrawer.java

/**
 * Creates a chart./*from   w  w w . ja v a 2 s .  c om*/
 *
 * @param dataset1  a dataset.
 *
 * @return A chart.
 */
private JFreeChart createChart(XYDataset dataset, long lastentry) {

    JFreeChart chart = ChartFactory.createTimeSeriesChart(name, // title
            "time", // x-axis label
            "temperature", // y-axis label
            dataset, // data
            true, // create legend?
            true, // generate tooltips?
            false // generate URLs?
    );

    chart.setBackgroundPaint(Color.white);

    XYPlot plot = (XYPlot) chart.getPlot();

    NumberAxis axis1 = new NumberAxis(getAxisName());
    axis1.setAutoRangeIncludesZero(isIncludeZero());
    plot.setRangeAxis(0, axis1);

    plot.setDataset(0, dataset);
    plot.mapDatasetToRangeAxis(1, 0);

    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);
    //TODO: SHADOWS OFF

    final StandardXYItemRenderer r1 = new StandardXYItemRenderer();
    plot.setRenderer(0, r1);
    r1.setSeriesPaint(0, Color.BLUE);
    r1.setSeriesPaint(1, Color.RED);
    r1.setSeriesPaint(2, Color.GREEN);

    //plot.setDomainAxis(new NumberAxis("time"));
    plot.setDomainAxis(new DateAxis());
    plot.getDomainAxis().setAutoRange(false);

    long begin = getRangeBegin(lastentry);
    long end = getRangeEnd(lastentry);

    plot.getDomainAxis().setRange(begin, end);

    return chart;
}

From source file:org.drools.planner.benchmark.core.report.BenchmarkReport.java

private XYPlot createScalabilityPlot(List<XYSeries> seriesList, String yAxisLabel, NumberFormat numberFormat) {
    NumberAxis xAxis = new NumberAxis("Problem scale");
    xAxis.setNumberFormatOverride(NumberFormat.getInstance(locale));
    NumberAxis yAxis = new NumberAxis(yAxisLabel);
    yAxis.setNumberFormatOverride(numberFormat);
    XYPlot plot = new XYPlot(null, xAxis, yAxis, null);
    int seriesIndex = 0;
    for (XYSeries series : seriesList) {
        XYSeriesCollection seriesCollection = new XYSeriesCollection();
        seriesCollection.addSeries(series);
        plot.setDataset(seriesIndex, seriesCollection);
        XYItemRenderer renderer = createScalabilityPlotRenderer(numberFormat);
        plot.setRenderer(seriesIndex, renderer);
        seriesIndex++;// w w w. ja  va 2 s . com
    }
    plot.setOrientation(PlotOrientation.VERTICAL);
    return plot;
}

From source file:MSUmpire.DIA.MixtureModelKDESemiParametric.java

public void GeneratePlot(String pngfile) throws IOException {
    String modelfile = FilenameUtils.getFullPath(pngfile) + "/" + FilenameUtils.getBaseName(pngfile)
            + "_ModelPoints.txt";
    FileWriter writer = new FileWriter(modelfile);

    double[] IDObs = new double[IDEmpiricalDist.getN()];
    double[] DecoyObs = new double[DecoyEmpiricalDist.getN()];

    for (int i = 0; i < IDEmpiricalDist.getN(); i++) {
        IDObs[i] = IDEmpiricalDist.getObs(i);
    }/*from w ww. ja  va2s . c  om*/
    for (int i = 0; i < DecoyEmpiricalDist.getN(); i++) {
        DecoyObs[i] = DecoyEmpiricalDist.getObs(i);
    }

    XYSeries model1 = new XYSeries("Incorrect matches");
    XYSeries model2 = new XYSeries("Correct matches");
    XYSeries model3 = new XYSeries("All target hits");

    writer.write("UScore\tModel\tCorrect\tDecoy\n");
    for (int i = 0; i < NoBinPoints; i++) {
        model1.add(model_kde_x[i], decoy_kde_y[i]);
        model2.add(model_kde_x[i], correct_kde_y[i]);
        model3.add(model_kde_x[i], model_kde_y[i]);
        writer.write(model_kde_x[i] + "\t" + model_kde_y[i] + "\t" + correct_kde_y[i] + "\t" + decoy_kde_y[i]
                + "\n");
    }
    writer.close();

    MixtureModelProb = new float[NoBinPoints + 1][3];
    float positiveaccu = 0f;
    float negativeaccu = 0f;

    MixtureModelProb[0][0] = (float) model2.getMaxX() + Float.MIN_VALUE;
    MixtureModelProb[0][1] = 1f;
    MixtureModelProb[0][2] = 1f;

    for (int i = 1; i < NoBinPoints + 1; i++) {
        double positiveNumber = correct_kde_y[NoBinPoints - i];
        double negativeNumber = decoy_kde_y[NoBinPoints - i];
        MixtureModelProb[i][0] = (float) model_kde_x[NoBinPoints - i];
        positiveaccu += positiveNumber;
        negativeaccu += negativeNumber;
        MixtureModelProb[i][2] = 0.999999f * (float) (positiveNumber / (negativeNumber + positiveNumber));
        MixtureModelProb[i][1] = 0.999999f * (float) (positiveaccu / (negativeaccu + positiveaccu));
    }

    XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.addSeries(model1);
    dataset.addSeries(model2);
    dataset.addSeries(model3);

    HistogramDataset histogramDataset = new HistogramDataset();
    histogramDataset.setType(HistogramType.SCALE_AREA_TO_1);
    histogramDataset.addSeries("ID hits", IDObs, 100);
    histogramDataset.addSeries("Decoy hits", DecoyObs, 100);
    //histogramDataset.addSeries("Model hits", ModelObs, 100);

    JFreeChart chart = ChartFactory.createHistogram(FilenameUtils.getBaseName(pngfile), "Score", "Hits",
            histogramDataset, PlotOrientation.VERTICAL, true, false, false);
    XYPlot plot = chart.getXYPlot();

    NumberAxis domain = (NumberAxis) plot.getDomainAxis();
    domain.setRange(min, max);
    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.setForegroundAlpha(0.8f);
    chart.setBackgroundPaint(Color.white);

    XYLineAndShapeRenderer render = new XYLineAndShapeRenderer();

    plot.setDataset(1, dataset);
    plot.setRenderer(1, render);
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
    try {
        ChartUtilities.saveChartAsPNG(new File(pngfile), chart, 1000, 600);
    } catch (IOException e) {
    }
}

From source file:flexflux.analyses.result.PP2DResult.java

public void plot() {

    JPanel panel = new JPanel();
    panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS));

    // one chart by group

    Map<Integer, Integer> correspGroup = new HashMap<Integer, Integer>();

    XYSeriesCollection dataset = new XYSeriesCollection();
    int index = 0;
    XYSeries series = new XYSeries("");
    for (double point : fluxValues) {

        series.add(point, resultValues.get(point));
        correspGroup.put(index, pointIndex.get(point));

        index++;// w w  w .ja va2  s. c  o m
    }

    dataset.addSeries(series);

    if (!expValues.isEmpty()) {
        XYSeries expSeries = new XYSeries("Experimental values");
        if (!expValues.isEmpty()) {
            for (Double d : expValues.keySet()) {
                for (Double d2 : expValues.get(d)) {
                    expSeries.add(d, d2);
                }
            }
        }

        dataset.addSeries(expSeries);
    }

    final JFreeChart chart = ChartFactory.createXYLineChart("", // chart
            // title
            reacName, // domain axis label
            objName, // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips
            false // urls
    );

    XYPlot plot = (XYPlot) chart.getPlot();

    plot.setBackgroundPaint(Color.WHITE);
    plot.setRangeGridlinePaint(Color.GRAY);
    plot.setDomainGridlinePaint(Color.GRAY);

    XYLineAndShapeRenderer renderer = new MyRenderer(true, false, correspGroup);

    plot.setRenderer(0, renderer);

    if (!expValues.isEmpty()) {
        renderer.setSeriesLinesVisible(1, false);
        renderer.setSeriesShapesVisible(1, true);
        renderer.setSeriesPaint(1, Color.BLUE);
    }

    ChartPanel chartPanel = new ChartPanel(chart);

    panel.add(chartPanel);

    JPanel fvaPanel = new JPanel();
    fvaPanel.setLayout(new BoxLayout(fvaPanel, BoxLayout.PAGE_AXIS));

    for (int i = 1; i <= groupIndex.size(); i++) {

        Color color = COLORLIST[i % COLORLIST.length];

        JPanel groupPanel = new JPanel();
        groupPanel.setLayout(new BoxLayout(groupPanel, BoxLayout.PAGE_AXIS));

        List<BioEntity> newEssentialReactions = comparator.getNewEssentialEntities().get(i);

        List<BioEntity> noLongerEssentialReactions = comparator.getNoLongerEssentialEntities().get(i);

        JPanel colorPanel = new JPanel();

        colorPanel.setBackground(color);

        groupPanel.add(colorPanel);
        groupPanel.add(new JLabel(
                "Phenotypic phase " + i + ", " + newEssentialReactions.size() + " new essential reactions"));

        fvaPanel.add(groupPanel);

        if (newEssentialReactions.size() > 0) {
            fvaPanel.add(new JScrollPane(comparator.getNewEssentialEntitiesPanel().get(i)));
        }

        fvaPanel.add(new JLabel("Phenotypic phase " + i + ", " + noLongerEssentialReactions.size()
                + " no longer essential reactions"));

        if (noLongerEssentialReactions.size() > 0) {
            fvaPanel.add(fvaPanel.add(new JScrollPane(comparator.getNoLongerEssentialEntitiesPanel().get(i))));
        }

    }

    JScrollPane fvaScrollPane = new JScrollPane(fvaPanel);

    JFrame frame = new JFrame("Phenotypic phase analysis results");

    if (expValues.size() > 0) {
        frame.setTitle("Pareto analysis two dimensions results");
    }

    if (groupIndex.size() > 0) {

        JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, panel, fvaScrollPane);
        frame.setContentPane(splitPane);
        frame.setSize(600, 1000);

    } else {
        frame.setContentPane(panel);
        frame.setSize(600, 600);
    }

    panel.setPreferredSize(new Dimension(600, 600));
    panel.setMinimumSize(new Dimension(600, 600));

    RefineryUtilities.centerFrameOnScreen(frame);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);

}

From source file:ca.nengo.plot.impl.DefaultPlotter.java

private void doPlot(float[] x, float[][] ideal, float[][] actual, int dim) {
    XYSeriesCollection dataset = new XYSeriesCollection();

    XYSeries idealSeries = new XYSeries("Ideal");
    for (int i = 0; i < x.length; i++) {
        idealSeries.add(x[i], ideal[i][dim]);
    }/*w ww  .ja  va  2 s  .  co  m*/
    dataset.addSeries(idealSeries);

    XYSeries actualSeries = new XYSeries("Actual");
    for (int i = 0; i < x.length; i++) {
        actualSeries.add(x[i], actual[i][dim]);
    }
    dataset.addSeries(actualSeries);

    JFreeChart chart = ChartFactory.createXYLineChart("Distortion", "X", "Estimate", dataset,
            PlotOrientation.VERTICAL, true, false, false);

    XYSeries errorSeries = new XYSeries("Error");
    float[][] error = MU.difference(actual, ideal);
    for (int i = 0; i < x.length; i++) {
        //         errorSeries.add(x[i], actual[i][dim] - ideal[i][dim]);
        errorSeries.add(x[i], error[i][dim]);
    }
    XYSeriesCollection errorDataset = new XYSeriesCollection();
    errorDataset.addSeries(errorSeries);
    NumberAxis errorAxis = new NumberAxis("Error");
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setRangeAxis(1, errorAxis);
    plot.setRangeAxisLocation(AxisLocation.TOP_OR_RIGHT);
    plot.setDataset(1, errorDataset);
    plot.mapDatasetToRangeAxis(1, 1);
    XYItemRenderer renderer = new XYLineAndShapeRenderer(true, false);
    plot.setRenderer(1, renderer);

    float[] err = MU.transpose(error)[dim];
    float mse = MU.prod(err, err) / (float) err.length;
    showChart(chart, "Distortion Error Plot (MSE=" + mse + ")");
}

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

@Override
public JFreeChart createChart() {
    XYPlot plot = new XYPlot();
    ValueAxis xAxis = this.axisBuilder.createValueAxis("% of Population Sorted by Income");
    xAxis.setRange(0.0, 102.0);//www.j  av  a2s.c om
    ValueAxis yAxis = this.axisBuilder.createValueAxis("Delta Utils [Utils]");
    yAxis.setRange(-0.05, 0.3);
    plot.setDomainAxis(xAxis);
    plot.setRangeAxis(yAxis);

    DgColorScheme colorScheme = new DgColorScheme();

    XYItemRenderer renderer2;
    renderer2 = new XYLineAndShapeRenderer(true, true);
    plot.setDataset(0, this.dataset);
    for (int i = 0; i <= 3; i++) {
        renderer2.setSeriesStroke(i, new BasicStroke(2.0f));
        renderer2.setSeriesOutlineStroke(i, new BasicStroke(3.0f));
        renderer2.setSeriesPaint(i, colorScheme.getColor(i + 1, "a"));
    }
    plot.setRenderer(0, renderer2);

    JFreeChart chart = new JFreeChart("", plot);
    chart.setBackgroundPaint(ChartColor.WHITE);
    chart.getLegend().setItemFont(this.axisBuilder.getAxisFont());
    chart.setTextAntiAlias(true);
    return chart;
}

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

/**
 * Creates an overlaid chart.//from  w  w w.  j  a  va  2 s .co m
 *
 * @return The chart.
 */
private JFreeChart createOverlaidChart() {

    // create plot ...
    final IntervalXYDataset data1 = createDataset1();
    final XYItemRenderer renderer1 = new XYBarRenderer(0.20);
    renderer1.setToolTipGenerator(
            new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT,
                    new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0.00")));
    final DateAxis domainAxis = new DateAxis("Date");
    domainAxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE);
    final ValueAxis rangeAxis = new NumberAxis("Value");
    final XYPlot plot = new XYPlot(data1, domainAxis, rangeAxis, renderer1);
    final double x = new Day(9, SerialDate.MARCH, 2002).getMiddleMillisecond();
    final XYTextAnnotation annotation = new XYTextAnnotation("Hello!", x, 10000.0);
    annotation.setFont(new Font("SansSerif", Font.PLAIN, 9));
    plot.addAnnotation(annotation);

    // add a second dataset and renderer...
    final XYDataset data2 = createDataset2();
    final XYItemRenderer renderer2 = new StandardXYItemRenderer();
    renderer2.setToolTipGenerator(
            new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT,
                    new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0.00")));
    plot.setDataset(1, data2);
    plot.setRenderer(1, renderer2);

    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

    // return a new chart containing the overlaid plot...
    return new JFreeChart("Overlaid Plot Example", JFreeChart.DEFAULT_TITLE_FONT, plot, true);

}