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

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

Introduction

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

Prototype

public void setDataset(int index, XYDataset dataset) 

Source Link

Document

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

Usage

From source file:msi.gama.outputs.layers.charts.ChartJFreeChartOutputHeatmap.java

@Override
protected void clearDataSet(final IScope scope) {
    // TODO Auto-generated method stub
    super.clearDataSet(scope);
    final XYPlot plot = (XYPlot) this.chart.getPlot();
    for (int i = plot.getDatasetCount() - 1; i >= 1; i--) {
        plot.setDataset(i, null);
        plot.setRenderer(i, null);//  ww w .  j  av  a  2s  . c o m
    }
    ((MatrixSeriesCollection) jfreedataset.get(0)).removeAllSeries();
    jfreedataset.clear();
    jfreedataset.add(0, new MatrixSeriesCollection());
    plot.setDataset((MatrixSeriesCollection) jfreedataset.get(0));
    plot.setRenderer(0, null);

    IdPosition.clear();
}

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

public JFreeChart createChart() {
    XYPlot plot = new XYPlot();
    ValueAxis xAxis = this.axisBuilder.createValueAxis("Income [Chf / Year]");
    ValueAxis yAxis = this.axisBuilder.createValueAxis("Delta Money [Chf]");
    plot.setDomainAxis(xAxis);//from ww  w.ja  va2s.  co m
    plot.setRangeAxis(yAxis);

    DgColorScheme colorScheme = new DgColorScheme();

    XYItemRenderer renderer2;
    renderer2 = new XYLineAndShapeRenderer(true, true);
    renderer2.setSeriesItemLabelsVisible(0, true);
    renderer2.setSeriesItemLabelGenerator(0, this.labelGenerator);
    plot.setDataset(0, this.dataset);
    renderer2.setSeriesStroke(0, new BasicStroke(2.0f));
    renderer2.setSeriesOutlineStroke(0, new BasicStroke(3.0f));
    renderer2.setSeriesPaint(0, colorScheme.getColor(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:playground.dgrether.analysis.charts.DgAvgDeltaUtilsGroupChart.java

public JFreeChart createChart() {
    XYPlot plot = new XYPlot();
    ValueAxis xAxis = this.axisBuilder.createValueAxis("Income [Chf / Year]");
    ValueAxis yAxis = this.axisBuilder.createValueAxis("Delta Utils [Utils]");
    plot.setDomainAxis(xAxis);//  ww  w.  j a  v a  2s  .  com
    plot.setRangeAxis(yAxis);

    DgColorScheme colorScheme = new DgColorScheme();

    XYItemRenderer renderer2;
    renderer2 = new XYLineAndShapeRenderer(true, true);
    renderer2.setSeriesItemLabelsVisible(0, true);
    renderer2.setSeriesItemLabelGenerator(0, this.labelGenerator);
    plot.setDataset(0, this.dataset);
    renderer2.setSeriesStroke(0, new BasicStroke(2.0f));
    renderer2.setSeriesOutlineStroke(0, new BasicStroke(3.0f));
    renderer2.setSeriesPaint(0, colorScheme.getColor(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:es.unex.meigas.extFillData.FittingDataPanel.java

private void createChart() {

    updateDataset();//w  w w .ja  v  a2s  .  c  om

    chart = ChartFactory.createScatterPlot(null, m_sParameters[m_XY.x], m_sParameters[m_XY.y], m_Data1,
            PlotOrientation.VERTICAL, false, true, true);

    final XYPlot plot = chart.getXYPlot();
    plot.setRenderer(new XYDotRenderer());
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);
    plot.getRenderer().setSeriesPaint(0, Color.blue);

    final XYItemRenderer renderer = new StandardXYItemRenderer();
    renderer.setSeriesPaint(0, Color.red);

    plot.setDataset(1, m_Data2);
    plot.setRenderer(1, renderer);

}

From source file:be.nbb.demetra.dfm.output.simulation.RMSEGraphView.java

private JFreeChart createChart() {
    JFreeChart result = ChartFactory.createXYBarChart("", "", false, "", Charts.emptyXYDataset(),
            PlotOrientation.VERTICAL, false, false, false);
    result.setPadding(TsCharts.CHART_PADDING);
    result.getTitle().setFont(TsCharts.CHART_TITLE_FONT);

    XYPlot plot = result.getXYPlot();

    plot.setDataset(DFM_INDEX, Charts.emptyXYDataset());
    plot.setRenderer(DFM_INDEX, dfmRenderer);
    plot.mapDatasetToDomainAxis(DFM_INDEX, 0);
    plot.mapDatasetToRangeAxis(DFM_INDEX, 0);

    plot.setDataset(ARIMA_INDEX, Charts.emptyXYDataset());
    plot.setRenderer(ARIMA_INDEX, arimaRenderer);
    plot.mapDatasetToDomainAxis(ARIMA_INDEX, 0);
    plot.mapDatasetToRangeAxis(ARIMA_INDEX, 0);

    plot.setDataset(STDEV_INDEX, Charts.emptyXYDataset());
    plot.setRenderer(STDEV_INDEX, stdevRenderer);
    plot.mapDatasetToDomainAxis(STDEV_INDEX, 0);
    plot.mapDatasetToRangeAxis(STDEV_INDEX, 0);

    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

    NumberAxis rangeAxis = new NumberAxis();
    rangeAxis.setAutoRangeIncludesZero(false);
    rangeAxis.setTickLabelPaint(TsCharts.CHART_TICK_LABEL_COLOR);
    plot.setRangeAxis(rangeAxis);/* w  w  w .  ja v a2  s  .c om*/

    NumberAxis domainAxis = new NumberAxis();
    domainAxis.setAutoRangeIncludesZero(false);
    domainAxis.setTickLabelPaint(TsCharts.CHART_TICK_LABEL_COLOR);
    plot.setDomainAxis(domainAxis);

    return result;
}

From source file:be.vds.jtbdive.client.view.core.dive.profile.DiveProfileChartFactory.java

public static JFreeChart createDiveProfileChartPanel(DiveProfile diveProfile, Locale locale,
        LengthUnit lengthUnit) {//w ww  .j av  a2  s.  c o m
    XYSeries depthSerie = new XYSeries(SERIE_DEPTH);
    XYSeriesCollection depthCollection = new XYSeriesCollection();
    depthCollection.addSeries(depthSerie);

    JFreeChart chart = ChartFactory.createXYAreaChart(null, getDomainLegend(locale),
            getRangeLegend(locale, lengthUnit), depthCollection, PlotOrientation.VERTICAL, false, true, false);
    XYPlot xyp = chart.getXYPlot();

    Paint p = new GradientPaint(0f, 0f, UIAgent.getInstance().getColorWaterBottom(), 200f, 200f,
            UIAgent.getInstance().getColorWaterSurface(), false);
    xyp.setBackgroundPaint(p);
    xyp.setDomainGridlinePaint(UIAgent.getInstance().getColorWaterGrid());
    xyp.setRangeGridlinePaint(UIAgent.getInstance().getColorWaterGrid());
    ((NumberAxis) xyp.getDomainAxis()).setNumberFormatOverride(new MinutesNumberFormat());

    XYAreaRenderer renderer0 = new XYAreaRenderer();
    renderer0.setOutline(true);
    renderer0.setBaseOutlinePaint(UIAgent.getInstance().getColorWaterBottom());

    Color baseColor = UIAgent.getInstance().getColorBaseBackground();
    renderer0.setSeriesPaint(0, new Color(baseColor.getRed(), baseColor.getGreen(), baseColor.getBlue(), 50));
    xyp.setRenderer(0, renderer0);

    int i = 1;

    XYSeriesCollection decoEntriesCollection = new XYSeriesCollection();
    XYSeries decoEntriesSerie = new XYSeries(SERIE_DECO_ENTRY);
    decoEntriesCollection.addSeries(decoEntriesSerie);
    XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer();
    renderer2.setSeriesLinesVisible(0, false);
    renderer2.setAutoPopulateSeriesShape(false);
    renderer2.setSeriesPaint(0, UIAgent.getInstance().getColorDecoEntries());
    renderer2.setBaseShape(DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE[SHAPE_DECO_ENTRY]);
    xyp.setDataset(i, decoEntriesCollection);
    xyp.setRenderer(i, renderer2);

    i++;
    XYSeriesCollection ascentTooFastCollection = new XYSeriesCollection();
    XYSeries ascentTooFastSerie = new XYSeries(SERIE_WARNING_ASCENT_TOO_FAST);
    ascentTooFastCollection.addSeries(ascentTooFastSerie);
    renderer2 = new XYLineAndShapeRenderer();
    renderer2.setSeriesLinesVisible(0, false);
    renderer2.setAutoPopulateSeriesShape(false);
    renderer2.setSeriesPaint(0, UIAgent.getInstance().getColorWarningAscentTooFast());
    renderer2.setBaseShape(DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE[SHAPE_ASCENT_TOO_FAST_WARNING]);
    xyp.setDataset(i, ascentTooFastCollection);
    xyp.setRenderer(i, renderer2);

    i++;
    XYSeriesCollection decoWarningCollection = new XYSeriesCollection();
    XYSeries decoWarningSerie = new XYSeries(SERIE_DECO_STOP);
    decoWarningCollection.addSeries(decoWarningSerie);
    renderer2 = new XYLineAndShapeRenderer();
    renderer2.setSeriesLinesVisible(0, false);
    renderer2.setAutoPopulateSeriesShape(false);
    renderer2.setSeriesPaint(0, UIAgent.getInstance().getColorWarningDecoCeiling());
    renderer2.setBaseShape(DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE[SHAPE_DECO_WARNING]);
    xyp.setDataset(i, decoWarningCollection);
    xyp.setRenderer(i, renderer2);

    i++;
    XYSeriesCollection remainBottomTimeCollection = new XYSeriesCollection();
    XYSeries remainBottomTimeSerie = new XYSeries(SERIE_REMAINING_BOTTOM_TIME);
    remainBottomTimeCollection.addSeries(remainBottomTimeSerie);
    renderer2 = new XYLineAndShapeRenderer();
    renderer2.setSeriesLinesVisible(0, false);
    renderer2.setAutoPopulateSeriesShape(false);
    renderer2.setSeriesPaint(0, UIAgent.getInstance().getColorWarningRemainingBottomTime());
    renderer2.setBaseShape(DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE[SHAPE_REMAINING_BOTTOM_TIME_WARNING]);
    xyp.setDataset(i, remainBottomTimeCollection);
    xyp.setRenderer(i, renderer2);

    Map<Double, Double> depthEntries = diveProfile.getDepthEntries();
    Set<Double> ascentWarning = diveProfile.getAscentWarnings();
    Set<Double> decoWarnings = diveProfile.getDecoCeilingWarnings();
    Set<Double> remainBottomTime = diveProfile.getRemainingBottomTimeWarnings();
    Set<Double> decoEntryTime = diveProfile.getDecoEntries();

    if (depthEntries.size() > 0 && depthEntries.get(0d) == null) {
        depthEntries.put(0d, 0d);
    }

    for (Double seconds : depthEntries.keySet()) {
        double d = UnitsAgent.getInstance().convertLengthFromModel(depthEntries.get(seconds), lengthUnit);
        depthSerie.add(seconds, Double.valueOf(d));
    }

    if (null != ascentWarning) {
        for (Double seconds : ascentWarning) {
            ascentTooFastSerie.add(seconds, depthEntries.get(seconds));
        }
    }

    if (null != decoWarnings) {
        for (Double seconds : decoWarnings) {
            decoWarningSerie.add(seconds, depthEntries.get(seconds));
        }
    }

    if (null != remainBottomTime) {
        for (Double seconds : remainBottomTime) {
            remainBottomTimeSerie.add(seconds, depthEntries.get(seconds));
        }
    }

    if (null != decoEntryTime) {
        for (Double seconds : decoEntryTime) {
            decoEntriesSerie.add(seconds, depthEntries.get(seconds));
        }
    }
    return chart;
}

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]);
    }//from   w w  w  .  jav  a2s  .c om
    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:jgnash.ui.commodity.SecuritiesHistoryDialog.java

private static JFreeChart createChart(final SecurityNode node) {
    Objects.requireNonNull(node);

    final List<SecurityHistoryNode> hNodes = node.getHistoryNodes();
    final Date max = DateUtils.asDate(hNodes.get(hNodes.size() - 1).getLocalDate());
    final Date min = DateUtils.asDate(hNodes.get(0).getLocalDate());

    final DateAxis timeAxis = new DateAxis(null);
    timeAxis.setVisible(false);//from   w  w w  .j a va 2 s .  c o m
    timeAxis.setAutoRange(false);
    timeAxis.setRange(min, max);

    final NumberAxis valueAxis = new NumberAxis(null);
    valueAxis.setAutoRangeIncludesZero(false);
    valueAxis.setVisible(false);

    final XYAreaRenderer renderer = new XYAreaRenderer();
    renderer.setBaseToolTipGenerator(new SecurityItemLabelGenerator(node));
    renderer.setOutline(true);
    renderer.setSeriesPaint(0, new Color(225, 247, 223));

    final XYPlot plot = new XYPlot(null, timeAxis, valueAxis, renderer);

    final List<List<SecurityHistoryNode>> groups = node.getHistoryNodeGroupsBySplits();

    for (int i = 0; i < groups.size(); i++) {
        int size = groups.get(i).size();

        Date[] date = new Date[size];
        double[] high = new double[size];
        double[] low = new double[size];
        double[] open = new double[size];
        double[] close = new double[size];
        double[] volume = new double[size];

        for (int j = 0; j < size; j++) {
            final SecurityHistoryNode hNode = groups.get(i).get(j);

            date[j] = DateUtils.asDate(hNode.getLocalDate());
            high[j] = hNode.getAdjustedHigh().doubleValue();
            low[j] = hNode.getAdjustedLow().doubleValue();
            open[j] = hNode.getAdjustedPrice().doubleValue();
            close[j] = hNode.getAdjustedPrice().doubleValue();
            volume[j] = hNode.getVolume();
        }

        final AbstractXYDataset data = new DefaultHighLowDataset(node.getDescription() + i, date, high, low,
                open, close, volume);
        plot.setDataset(i, data);
    }

    plot.setInsets(new RectangleInsets(1, 1, 1, 1));

    final JFreeChart chart = new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, plot, false);
    chart.setBackgroundPaint(null);

    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++;//www  . jav  a  2s. c  om
    }
    plot.setOrientation(PlotOrientation.VERTICAL);
    return plot;
}

From source file:controletanquesproj1.Grafico.java

/**
 * Creates a chart.//  w ww.j av  a  2  s. com
 * 
 * @param _datasets
 * @param datasets
 * @param dataset  the data for the chart.
 * 
 * @return a chart.
 */
public JFreeChart createChart() {

    // create the chart...
    final JFreeChart chart = ChartFactory.createXYLineChart("", // chart title
            "Amostra", // x axis label
            "Amplitude (V)", // y axis label
            getDatasets()[0], // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips
            false // urls
    );

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    chart.setBackgroundPaint(Color.white);

    //        final StandardLegend legend = (StandardLegend) chart.getLegend();
    //      legend.setDisplaySeriesShapes(true);

    // get a reference to the plot for further customisation...
    final XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.white);
    //    plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
    plot.setDomainGridlinePaint(Color.black);
    plot.setRangeGridlinePaint(Color.black);
    plot.getRangeAxis(0).setRange(-30, 30);

    final NumberAxis axis2 = new NumberAxis("Altura (cm)");
    axis2.setAutoRange(true);
    axis2.setAutoRangeIncludesZero(false);

    //axis2.setRange(-4.9, 34.9);
    plot.setRangeAxis(1, axis2);
    plot.setDataset(1, getDatasets()[1]);
    plot.mapDatasetToRangeAxis(1, 1);

    /*
    getRenderer().setSeriesLinesVisible(0, true);
    getRenderer().setSeriesShapesVisible(0, false);
    getRenderer().setSeriesShapesVisible(1, false);
    getRenderer().setSeriesShapesVisible(2, false);
    getRenderer().setSeriesLinesVisible(3, true);
    getRenderer().setSeriesShapesVisible(3, false);
    */

    renderer[0].setBaseShapesVisible(false);
    renderer[0].setAutoPopulateSeriesPaint(true);

    plot.setRenderer(renderer[0]);

    renderer[1] = new XYLineAndShapeRenderer();
    renderer[1].setBaseLinesVisible(true);
    renderer[1].setBaseShapesVisible(true);

    plot.setRenderer(1, renderer[1]);

    // change the auto tick unit selection to integer units only...
    //final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    //rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    // OPTIONAL CUSTOMISATION COMPLETED.

    return chart;

}