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:cn.InstFS.wkr.NetworkMining.UIs.TimeSeriesChart2.java

public static JFreeChart createChart(DataItems nor, DataItems abnor, String title, String protocol1,
        String protocol2) {/*ww  w.  j av a  2 s.  c om*/
    // ?
    XYDataset xydataset1 = TimeSeriesChart1.createNormalDataset(nor, protocol1);
    JFreeChart jfreechart = ChartFactory.createScatterPlot(title, "", "", xydataset1);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();

    XYLineAndShapeRenderer xylineandshaperenderer1 = (XYLineAndShapeRenderer) xyplot.getRenderer();
    // ??1?1

    NumberAxis numberaxis = (NumberAxis) xyplot.getRangeAxis();
    numberaxis.setAutoRangeIncludesZero(false);
    java.awt.geom.Ellipse2D.Double double1 = new java.awt.geom.Ellipse2D.Double(-4D, -4D, 6D, 6D);
    // ???

    // ??
    xylineandshaperenderer1.setSeriesLinesVisible(0, true);
    xylineandshaperenderer1.setBaseShapesVisible(false);
    xylineandshaperenderer1.setSeriesShape(0, double1);
    xylineandshaperenderer1.setSeriesPaint(0, Color.blue);
    xylineandshaperenderer1.setSeriesFillPaint(0, Color.blue);
    xylineandshaperenderer1.setSeriesOutlinePaint(0, Color.blue);
    xylineandshaperenderer1.setSeriesStroke(0, new BasicStroke(0.5F));

    // ?
    XYDataset xydataset2 = TimeSeriesChart1.createNormalDataset(abnor, protocol2);
    /*      XYTextAnnotation localXYTextAnnotation = new XYTextAnnotation("aa",10,
    Double.parseDouble(abnor.getElementAt(10).getData()));
          xyplot.addAnnotation(localXYTextAnnotation);*/
    XYLineAndShapeRenderer xylineandshaperenderer2 = new XYLineAndShapeRenderer();
    int datasetcount = xyplot.getDatasetCount();
    xyplot.setDataset(datasetcount, xydataset2);
    xyplot.setRenderer(datasetcount, xylineandshaperenderer2);
    /*      System.out.println("DatasetCount="+xyplot.getDatasetCount());
                  
          for(int c=0;c<xyplot.getDatasetCount();c++){
             System.out.println("DatasetSeriesCount="+xyplot.getDataset(c).getSeriesCount());
             System.out.println("Dataset["+c+"]="+xyplot.getDataset(c).getSeriesKey(0));
          }*/

    /*   // ??? 
       xylineandshaperenderer2.setBaseShapesVisible(false);
       // ??
       xylineandshaperenderer2.setSeriesLinesVisible(0, true);
       xylineandshaperenderer2.setSeriesShape(0, double1);
       // 
       xylineandshaperenderer2.setSeriesPaint(0, Color.green);
       xylineandshaperenderer2.setSeriesFillPaint(0, Color.green);
       xylineandshaperenderer2.setSeriesOutlinePaint(0, Color.green);
            
       xylineandshaperenderer2.setUseFillPaint(true);
       xylineandshaperenderer2
    .setBaseItemLabelGenerator(new StandardXYItemLabelGenerator());
       xylineandshaperenderer2.setSeriesStroke(0, new BasicStroke(0.5F));
               
    */
    xylineandshaperenderer2.setSeriesLinesVisible(0, true);
    xylineandshaperenderer2.setBaseShapesVisible(false);
    xylineandshaperenderer2.setSeriesShape(0, double1);
    xylineandshaperenderer2.setSeriesPaint(0, Color.GREEN);
    xylineandshaperenderer2.setSeriesFillPaint(0, Color.GREEN);
    xylineandshaperenderer2.setSeriesOutlinePaint(0, Color.green);
    xylineandshaperenderer2.setSeriesStroke(0, new BasicStroke(0.5F));
    jfreechart.getLegend().setVisible(true);
    return jfreechart;

}

From source file:be.nbb.demetra.dfm.output.ConfidenceGraph.java

private void onDataChange() {
    chartPanel.getChart().setNotify(false);

    XYPlot plot = chartPanel.getChart().getXYPlot();

    plot.setDataset(ORIGINAL_DATA_INDEX,
            (data.original == null ? null : TsXYDatasets.from("data", data.original)));

    if (data.series != null && data.stdev != null) {
        plot.setDataset(MAIN_INDEX, TsXYDatasets.from("series", data.series));

        TsData stdev60 = data.stdev.times(0.84); // Confidence of 60%
        TsData stdev70 = data.stdev.times(1.035); // Confidence of 70%
        TsData stdev80 = data.stdev.times(1.28); // Confidence of 80%
        TsData stdev90 = data.stdev.times(1.645); // Confidence of 90%
        TsData stdev95 = data.stdev.times(1.96); // Confidence of 95%
        TsData stdev99 = data.stdev.times(2.575); // Confidence of 99%
        TsData diff6070 = stdev70.minus(stdev60).div(intermediateValues);
        TsData diff7080 = stdev80.minus(stdev70).div(intermediateValues);
        TsData diff8090 = stdev90.minus(stdev80).div(intermediateValues);
        TsData diff9095 = stdev95.minus(stdev90).div(intermediateValues);
        TsData diff9599 = stdev99.minus(stdev95).div(intermediateValues);

        TsData[] stdevs = { stdev60, stdev70, stdev80, stdev90, stdev95 };
        TsData[] diffs = { diff6070, diff7080, diff8090, diff9095, diff9599 };

        for (int i = 0; i < stdevs.length; i++) {
            plot.setDataset(indexes[i], TsXYDatasets.builder().add("lower", data.series.minus(stdevs[i]))
                    .add("upper", data.series.plus(stdevs[i])).build());
            for (int j = 1; j < intermediateValues; j++) {
                TsData l = data.series.minus(stdevs[i]).minus(diffs[i].times(j));
                TsData u = data.series.plus(stdevs[i]).plus(diffs[i].times(j));
                plot.setDataset(indexes[i] - j,
                        TsXYDatasets.builder().add("lower" + j, l).add("upper" + j, u).build());
            }//from w  ww . j a v a2  s .c  o m
        }

        plot.setDataset(CONFIDENCE99_INDEX, TsXYDatasets.builder().add("lower99", data.series.minus(stdev99))
                .add("upper99", data.series.plus(stdev99)).build());

    } else {
        plot.setDataset(MAIN_INDEX, null);

        for (int i = 0; i < indexes.length; i++) {
            plot.setDataset(indexes[i], null);
            if (i != indexes.length - 1) {
                for (int j = 1; j < intermediateValues; j++) {
                    plot.setDataset(indexes[i] - j, null);
                }
            }
        }
    }
    onDataFormatChange();

    chartPanel.getChart().setNotify(true);
}

From source file:ucar.unidata.idv.control.chart.VerticalProfileChart.java

/**
 * Initialize the plot/*from   www .  j ava 2  s .  c  o m*/
 *
 * @param plot the plot to initialize
 */
protected void initPlot(Plot plot) {
    XYPlot xyPlot = (XYPlot) plot;
    xyPlot.setOrientation(PlotOrientation.HORIZONTAL);

    int count = xyPlot.getDatasetCount();
    for (int i = 0; i < count; i++) {
        xyPlot.setDataset(i, null);
        xyPlot.setRenderer(i, null);
    }
    xyPlot.clearRangeAxes();
    XYSeriesCollection dummyDataset = new XYSeriesCollection();
    //ValueAxis          rangeAxis    = new FixedWidthNumberAxis();
    ValueAxis rangeAxis = new NumberAxis();
    xyPlot.setRangeAxis(0, rangeAxis, false);
    xyPlot.setDataset(0, dummyDataset);
    xyPlot.mapDatasetToRangeAxis(0, 0);
    xyPlot.setRenderer(0, new XYLineAndShapeRenderer());
}

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

/**
 * Processes and displays the inserted items
 *///from www  .j  a  v  a 2 s  . c o  m
public void display() {
    BasicXYDataset pointsDataset = new BasicXYDataset();
    BasicXYDataset meanDataset = new BasicXYDataset();
    BasicXYDataset smoothDataset = new BasicXYDataset();
    int np = items.get(0).getDataArray().length - 1;
    double xstart = -0.4;
    double xend = 0.4;
    final double xstep = 0.8 / np;
    boolean smoothData;

    String[] itemNames = new String[items.size()];
    for (int i = 0; i < items.size(); i++) {
        itemNames[i] = items.get(i).name;
    }

    for (int i = 0; i < items.size(); i++) {
        double x = xstart;
        StabilityViewItem it = items.get(i);
        double[] array = it.getDataArray();
        if (array != null && array.length > 0) {
            smoothData = false;

            int n = array.length;
            double m = it.getAverage();
            double[] meanX = { xstart, xend };
            double[] mean2X = { 0, n - 1 };
            double[] meanY = { m, m };
            double[] pointsX = new double[n], points2X = new double[n];
            double[] pointsY = new double[n], points2Y = new double[n];
            double[] smoothX = new double[n], smooth2X = new double[n];
            double[] smoothY = new double[n], smooth2Y = new double[n];

            // Inserts the data (points)
            for (int j = 0; j < n; j++) {
                pointsX[j] = x;
                pointsY[j] = array[j];
                points2X[j] = j;
                points2Y[j] = array[j];
                x += xstep;
            }

            // Inserts the smoothed data if it's present
            if (it.smoothedData != null && it.smoothedData.length > 0) {
                smoothData = true;
                for (int j = 0; j < n; j++) { // Add of points
                    smoothX[j] = x;
                    smoothY[j] = it.smoothedData[j];
                    smooth2X[j] = j;
                    smooth2Y[j] = it.smoothedData[j];
                    x += xstep;
                }
            }

            BasicXYDataset.Series mean = BasicXYDataset.Series.of(itemNames[i], meanX, meanY);
            BasicXYDataset.Series mean2 = BasicXYDataset.Series.of(itemNames[i], mean2X, meanY);
            BasicXYDataset.Series points = BasicXYDataset.Series.of(itemNames[i], pointsX, pointsY);
            BasicXYDataset.Series points2 = BasicXYDataset.Series.of(itemNames[i], points2X, points2Y);
            BasicXYDataset.Series smooth = smoothData ? BasicXYDataset.Series.of(itemNames[i], smoothX, smoothY)
                    : BasicXYDataset.Series.empty(itemNames[i]);
            BasicXYDataset.Series smooth2 = smoothData
                    ? BasicXYDataset.Series.of(itemNames[i], smooth2X, smooth2Y)
                    : BasicXYDataset.Series.empty(itemNames[i]);

            Bornes b = new Bornes(xstart, xend);
            Graphs g = new Graphs(mean2, points2, smooth2, itemNames[i]);
            graphs_.put(b, g); // Map used to display detail chart on double click

            smoothDataset.addSeries(smooth);
            meanDataset.addSeries(mean);
            pointsDataset.addSeries(points);
        }

        xstart++;
        xend++;
    }

    XYPlot plot = mainChart.getXYPlot();
    configureAxis(plot);
    plot.setDataset(SMOOTH_INDEX, smoothDataset);
    plot.setDataset(MEAN_INDEX, meanDataset);
    plot.setDataset(POINTS_INDEX, pointsDataset);

    showMain();
}

From source file:grafix.graficos.eixos.EixoCandles.java

protected void completarPlot(final XYPlot plot, final JanelaGraficos janela) {
    OHLCDataset dataCandles = criarOHLCDataset(janela);
    CandlestickRenderer candRenderer = new CandlestickRenderer();
    candRenderer.setUpPaint(Controle.getConfiguracoesUsuario().getCorCandlesAlta());
    candRenderer.setDownPaint(Controle.getConfiguracoesUsuario().getCorCandlesBaixa());
    candRenderer.setSeriesPaint(0, Color.black);
    candRenderer.setStroke(new BasicStroke(.75f));
    candRenderer.setToolTipGenerator(new CandlesToolTipGenerator(janela));
    plot.setDataset(indices.size(), dataCandles);
    plot.setRenderer(indices.size(), candRenderer);
    incluirMarcaIntraday(plot, janela);/*  ww w .  ja  va  2 s.c om*/
}

From source file:org.signserver.client.cli.performance.PerformanceTestPDFServlet.java

License:asdf

/**
 * Create and write diagrams to disk.//from   w w  w .j  a  v a  2 s.  c  o m
 */
private void createDiagram(String statisticsDirectory, ArrayList<String> explanationRow,
        ArrayList<ArrayList<Double>> processedData, int xRow, int y1Row, int y2Row) {
    final XYSeries s1 = new XYSeries(explanationRow.get(y1Row));
    final XYSeries s2 = new XYSeries(explanationRow.get(y2Row));
    for (ArrayList<Double> currentRow : processedData) {
        s1.add(currentRow.get(xRow), currentRow.get(y1Row));
        s2.add(currentRow.get(xRow), currentRow.get(y2Row));
    }
    final XYSeriesCollection dataset1 = new XYSeriesCollection();
    dataset1.addSeries(s1);
    final XYSeriesCollection dataset2 = new XYSeriesCollection();
    dataset2.addSeries(s2);
    final JFreeChart chart = ChartFactory.createXYLineChart("Test result " + xRow + "" + y1Row + "" + y2Row,
            explanationRow.get(xRow), explanationRow.get(y1Row), dataset1, PlotOrientation.VERTICAL, true, true,
            false);
    final XYPlot plot = chart.getXYPlot();
    if (y1Row == COLUMN_INVOCATIONS_PER_SECOND) {
        final NumberAxis axis1 = new LogarithmicAxis(explanationRow.get(y1Row));
        plot.setRangeAxis(0, axis1);
    }
    final NumberAxis axis2 = new NumberAxis(explanationRow.get(y2Row));
    axis2.setAutoRangeIncludesZero(false);
    plot.setRangeAxis(1, axis2);
    plot.setDataset(1, dataset2);
    plot.mapDatasetToRangeAxis(1, 1);
    final StandardXYItemRenderer renderer2 = new StandardXYItemRenderer();
    renderer2.setSeriesPaint(0, Color.BLUE);
    plot.setRenderer(1, renderer2);
    final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
    final File file = new File(
            statisticsDirectory + "PDF Signatures" + "-" + xRow + "" + y1Row + "" + y2Row + ".png");
    int imageWidth = 800;
    int imageHeight = 600;
    try {
        System.out.println("Writing diagram to " + file.getName());
        System.out.flush();
        ChartUtilities.saveChartAsPNG(file, chart, imageWidth, imageHeight, info);
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.bdb.weather.display.freeplot.FreePlotSeriesCollection.java

/**
 * Constructor.//from   w w w . j  a  va 2s.co  m
 * 
 * @param groupName The name of this group
 * @param units The units of this collection, used to setup the Range Axis
 * @param datasetIndex The dataset index from a JFreePlot perspective
 * @param domainAxisIndex The index of the domain axis, from a JFreeChart perspective
 * @param plot The plot to which the dataset and axis will be added
 * @param stroke The Stroke used to draw the series of this collection
 * @param factory The factory used to create the series
 */
FreePlotSeriesCollection(String groupName, Unit units, int datasetIndex, int domainAxisIndex, XYPlot plot,
        Stroke stroke, SeriesFactory<T> factory) {
    this.groupName = groupName;
    this.dataset = new TimeSeriesCollection();
    this.datasetIndex = datasetIndex;
    this.factory = factory;
    this.plot = plot;
    renderer = new DefaultXYItemRenderer();
    renderer.setBaseShapesVisible(false);
    renderer.setBaseToolTipGenerator(StandardXYToolTipGenerator.getTimeSeriesInstance());
    renderer.setDrawSeriesLineAsPath(true);
    plot.setDataset(datasetIndex, dataset);
    plot.setRenderer(datasetIndex, renderer);
    series = factory.createSeriesGroup(groupName, stroke);
    plot.mapDatasetToDomainAxis(datasetIndex, domainAxisIndex);
}

From source file:com.signalcollect.sna.gephiconnectors.SignalCollectGephiConnector.java

/**
 * Creates the Chart of the Degree Distribution according to the calculated
 * distribution/*w ww.j  a v a2 s . co  m*/
 * 
 * @param degreeDistribution
 * @return a {@link JFreeChart} containing the distribution of degrees in
 *         the graph
 * @throws IOException
 */
public JFreeChart createDegreeDistributionChart(Map<Integer, Integer> degreeDistribution) throws IOException {
    XYSeries dSeries = new XYSeries("number of occurences");
    for (Iterator it = degreeDistribution.entrySet().iterator(); it.hasNext();) {
        Map.Entry d = (Map.Entry) it.next();
        Number x = (Number) d.getKey();
        Number y = (Number) d.getValue();
        dSeries.add(x, y);
    }
    XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.addSeries(dSeries);
    dataset.setAutoWidth(true);

    JFreeChart chart = ChartFactory.createHistogram("Degree Distribution", "Degree centrality value",
            "number of occurences", dataset, PlotOrientation.VERTICAL, true, true, true);

    XYPlot plot = chart.getXYPlot();
    XYBarRenderer renderer0 = new XYBarRenderer();
    Font font = new Font("Font", 0, 14);
    renderer0.setMargin(0.2);
    renderer0.setBaseItemLabelGenerator(new StandardXYItemLabelGenerator());
    renderer0.setBaseItemLabelsVisible(true);
    renderer0.setBaseItemLabelFont(font);
    plot.setDataset(0, dataset);
    plot.setRenderer(0, renderer0);
    plot.getRendererForDataset(plot.getDataset(0)).setSeriesPaint(0, Color.BLUE);
    return chart;
}

From source file:org.graphstream.algorithm.measure.ChartMinMaxAverageSeriesMeasure.java

public JFreeChart createChart(PlotParameters params) throws PlotException {
    XYSeriesCollection minMax = new XYSeriesCollection();
    XYSeriesCollection avgCol = new XYSeriesCollection();
    XYPlot plot;
    XYBarRenderer r = new XYBarRenderer();
    r.setBarPainter(new StandardXYBarPainter());
    r.setMargin(0.35);//w  w w.  ja  v  a  2 s . c o m

    minMax.addSeries(min);
    avgCol.addSeries(series);
    minMax.addSeries(max);

    JFreeChart chart = ChartFactory.createXYLineChart(params.title, params.xAxisLabel, params.yAxisLabel,
            avgCol, params.orientation, params.showLegend, true, false);

    plot = ((XYPlot) chart.getPlot());
    plot.setDataset(1, minMax);
    plot.setRenderer(1, r);

    if (separateMinMaxAxis) {
        NumberAxis minMaxAxis = new NumberAxis("min/max");

        plot.setRangeAxis(1, minMaxAxis);
        plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT);
        plot.mapDatasetToRangeAxis(1, 1);
    }

    return chart;
}

From source file:com.signalcollect.sna.gephiconnectors.SignalCollectGephiConnector.java

/**
 * Creates the Chart of the Clustering Distribution according to the
 * calculated distribution//from   w w  w .ja v a2 s. c o m
 * 
 * @param clusterDistribution
 * @return a {@link JFreeChart} containing the distribution of local cluster
 *         coefficients in the graph
 * @throws IOException
 */
public JFreeChart createClusterDistributionChart(Map<Double, Integer> clusterDistribution) throws IOException {
    XYSeries dSeries = new XYSeries("number of occurences");
    for (Iterator it = clusterDistribution.entrySet().iterator(); it.hasNext();) {
        Map.Entry d = (Map.Entry) it.next();
        Number x = (Number) d.getKey();
        Number y = (Number) d.getValue();
        dSeries.add(x, y);
    }
    XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.addSeries(dSeries);
    dataset.setAutoWidth(true);

    JFreeChart chart = ChartFactory.createHistogram("Local Cluster Coefficient Distribution",
            "Local Cluster Coefficient value", "number of occurences", dataset, PlotOrientation.VERTICAL, true,
            true, true);

    XYPlot plot = chart.getXYPlot();
    XYBarRenderer renderer0 = new XYBarRenderer();
    Font font = new Font("Font", 0, 14);
    renderer0.setMargin(0.2);
    renderer0.setBaseItemLabelGenerator(new StandardXYItemLabelGenerator());
    renderer0.setBaseItemLabelsVisible(true);
    renderer0.setBaseItemLabelFont(font);
    plot.setDataset(0, dataset);
    plot.setRenderer(0, renderer0);

    plot.getRendererForDataset(plot.getDataset(0)).setSeriesPaint(0, Color.BLUE);

    return chart;
}