Example usage for org.jfree.data.xy XYSeries updateByIndex

List of usage examples for org.jfree.data.xy XYSeries updateByIndex

Introduction

In this page you can find the example usage for org.jfree.data.xy XYSeries updateByIndex.

Prototype

public void updateByIndex(int index, Number y) 

Source Link

Document

Updates the value of an item in the series and sends a SeriesChangeEvent to all registered listeners.

Usage

From source file:carfuzzy.Operations.java

public JFreeChart setYAxisForImplication(double imp, XYSeries series, XYSeriesCollection collection,
        Output out) {//  w w  w .  j a  v  a 2s .  c o m
    JFreeChart chart;
    if (out == Output.stop) {
        series.updateByIndex(0, imp);
        series.updateByIndex(1, imp);
        series.updateByIndex(2, imp);
    } else if (out == Output.speedUp) {
        series.updateByIndex(1, imp);
        series.updateByIndex(2, imp);
        series.updateByIndex(3, imp);
    } else {
        series.updateByIndex(1, imp);
        series.updateByIndex(2, imp);
    }
    collection.addSeries(series);
    String x_axis = "Implication";

    chart = XYGraph.drawChart(collection, x_axis, "Membership");
    XYPlot plot = chart.getXYPlot();
    ValueAxis xaxis = plot.getDomainAxis();
    xaxis.setRange(0, 10);
    XYItemRenderer renderer = plot.getRenderer();
    renderer.setSeriesStroke(0, new BasicStroke(3.5f));
    return chart;
}

From source file:com.anrisoftware.prefdialog.miscswing.multichart.freechart.FreechartXYChart.java

private void updateData0(int row0, int row1, int offset) {
    ChartModel model = this.model;
    XYSeriesCollection series = getCategory();
    int col0 = 0;
    int col1 = series.getSeriesCount() - 1;
    for (int col = col0; col <= col1; col++) {
        XYSeries xyseries = series.getSeries(col);
        for (int row = row0; row <= row1; row++) {
            double value = model.getValueAt(row + offset, col);
            xyseries.updateByIndex(row, value);
        }/*from   w ww .ja  va2 s  . co  m*/
    }
}

From source file:org.jfree.data.xy.XYSeriesTest.java

/**
 * Some checks for the updateByIndex() method.
 *///ww  w  . ja v  a2s .  c  o m
@Test
public void testUpdateByIndex3() {
    XYSeries s1 = new XYSeries("S1");
    s1.add(1.0, 1.1);
    s1.add(2.0, 2.2);
    s1.add(3.0, 3.3);

    s1.updateByIndex(1, new Double(2.05));
    assertEquals(1.1, s1.getMinY(), EPSILON);
    assertEquals(3.3, s1.getMaxY(), EPSILON);
}

From source file:opendial.gui.stateviewer.DistributionViewer.java

private List<XYSeries> extractSeries(DensityFunction function) throws DialException {

    List<XYSeries> series = new ArrayList<XYSeries>();

    for (int i = 0; i < function.getDimensionality(); i++) {
        series.add(new XYSeries("dimension " + i));
    }/*from w  w  w.j  a  v  a 2s.co m*/

    Consumer<double[]> addToSeries = p -> {
        double density = function.getDensity(p);
        for (int d = 0; d < p.length; d++) {
            series.get(d).add(p[d], density);
        }
    };

    Set<double[]> points = function.discretise(500).keySet();
    points.stream().forEach(addToSeries);

    for (XYSeries serie : series) {
        boolean doSmoothing = (function instanceof KernelDensityFunction)
                || (function instanceof DirichletDensityFunction);
        while (doSmoothing) {
            int nbFluctuations = 0;
            double prevPrevY = serie.getY(0).doubleValue();
            double prevY = serie.getY(1).doubleValue();
            for (int i = 2; i < serie.getItemCount(); i++) {
                double currentY = serie.getY(i).doubleValue();
                if (Math.signum(prevY - prevPrevY) != Math.signum(currentY - prevY)) {
                    double avg = (prevPrevY + prevY + currentY) / 3.0;
                    serie.updateByIndex(i - 2, avg);
                    serie.updateByIndex(i - 1, avg);
                    serie.updateByIndex(i, avg);
                    nbFluctuations++;
                }
                prevPrevY = prevY;
                prevY = currentY;
            }
            doSmoothing = (nbFluctuations > points.size() / 2) ? true : false;
        }

    }
    return series;
}

From source file:opendial.gui.utils.DistributionViewer.java

private List<XYSeries> extractSeries(DensityFunction function) {

    List<XYSeries> series = new ArrayList<XYSeries>();

    for (int i = 0; i < function.getDimensions(); i++) {
        series.add(new XYSeries("dimension " + i));
    }/*www .ja  v  a2 s .c  o  m*/

    Consumer<double[]> addToSeries = p -> {
        double density = function.getDensity(p);
        for (int d = 0; d < p.length; d++) {
            series.get(d).add(p[d], density);
        }
    };

    Set<double[]> points = function.discretise(500).keySet();
    points.stream().forEach(addToSeries);

    for (XYSeries serie : series) {
        boolean doSmoothing = (function instanceof KernelDensityFunction)
                || (function instanceof DirichletDensityFunction);
        while (doSmoothing) {
            int nbFluctuations = 0;
            double prevPrevY = serie.getY(0).doubleValue();
            double prevY = serie.getY(1).doubleValue();
            for (int i = 2; i < serie.getItemCount(); i++) {
                double currentY = serie.getY(i).doubleValue();
                if (Math.signum(prevY - prevPrevY) != Math.signum(currentY - prevY)) {
                    double avg = (prevPrevY + prevY + currentY) / 3.0;
                    serie.updateByIndex(i - 2, avg);
                    serie.updateByIndex(i - 1, avg);
                    serie.updateByIndex(i, avg);
                    nbFluctuations++;
                }
                prevPrevY = prevY;
                prevY = currentY;
            }
            doSmoothing = (nbFluctuations > points.size() / 2) ? true : false;
        }

    }
    return series;
}

From source file:org.jfree.data.xy.XYSeriesTest.java

/**
 * Some checks for the updateByIndex() method.
 *//*  ww  w .j  ava2s  . c  om*/
@Test
public void testUpdateByIndex2() {
    XYSeries s1 = new XYSeries("S1");
    s1.add(1.0, Double.NaN);

    assertTrue(Double.isNaN(s1.getMinY()));
    assertTrue(Double.isNaN(s1.getMaxY()));

    s1.updateByIndex(0, new Double(1.0));
    assertEquals(1.0, s1.getMinY(), EPSILON);
    assertEquals(1.0, s1.getMaxY(), EPSILON);

    s1.updateByIndex(0, new Double(2.0));
    assertEquals(2.0, s1.getMinY(), EPSILON);
    assertEquals(2.0, s1.getMaxY(), EPSILON);

    s1.add(-1.0, -1.0);
    s1.updateByIndex(0, new Double(0.0));
    assertEquals(0.0, s1.getMinY(), EPSILON);
    assertEquals(2.0, s1.getMaxY(), EPSILON);
}

From source file:com.vgi.mafscaling.MafChartPanel.java

public void movePoint(MouseEvent event) {
    try {/*from   w ww  .j a  v  a2  s .c  om*/
        if (IsMovable) {
            int itemIndex = xyItemEntity.getItem();
            int seriesIndex = xyItemEntity.getSeriesIndex();
            if (!pointDraggableSet.contains(seriesIndex))
                return;
            XYSeries series = ((XYSeriesCollection) xyItemEntity.getDataset()).getSeries(seriesIndex);
            XYPlot plot = chartPanel.getChart().getXYPlot();
            Rectangle2D dataArea = chartPanel.getChartRenderingInfo().getPlotInfo().getDataArea();
            Point2D p = chartPanel.translateScreenToJava2D(event.getPoint());
            double finalMovePointY = plot.getRangeAxis().java2DToValue(p.getY(), dataArea,
                    plot.getRangeAxisEdge());
            double difference = finalMovePointY - initialMovePointY;
            if (series.getY(itemIndex).doubleValue() + difference > plot.getRangeAxis().getRange().getLength()
                    || series.getY(itemIndex).doubleValue() + difference < 0.0)
                initialMovePointY = finalMovePointY;
            series.updateByIndex(itemIndex, series.getY(itemIndex).doubleValue() + difference);
            chartHolder.onMovePoint(itemIndex, series.getX(itemIndex).doubleValue(),
                    series.getY(itemIndex).doubleValue());
            chartPanel.getChart().fireChartChanged();
            chartPanel.updateUI();
            initialMovePointY = finalMovePointY;
        }
    } catch (Exception e) {
        e.printStackTrace();
        logger.error(e);
    }
}

From source file:org.jfree.data.xy.XYSeriesTest.java

/**
 * Some checks for the updateByIndex() method.
 *///w  w  w.  j  a v a  2 s.c  om
@Test
public void testUpdateByIndex() {
    XYSeries s1 = new XYSeries("S1");
    s1.add(1.0, 1.1);
    s1.add(2.0, 2.2);
    s1.add(3.0, 3.3);

    assertEquals(1.1, s1.getMinY(), EPSILON);
    assertEquals(3.3, s1.getMaxY(), EPSILON);

    s1.updateByIndex(0, new Double(-5.0));
    assertEquals(-5.0, s1.getMinY(), EPSILON);
    assertEquals(3.3, s1.getMaxY(), EPSILON);

    s1.updateByIndex(0, null);
    assertEquals(2.2, s1.getMinY(), EPSILON);
    assertEquals(3.3, s1.getMaxY(), EPSILON);

    s1.updateByIndex(2, null);
    assertEquals(2.2, s1.getMinY(), EPSILON);
    assertEquals(2.2, s1.getMaxY(), EPSILON);

    s1.updateByIndex(1, null);
    assertTrue(Double.isNaN(s1.getMinY()));
    assertTrue(Double.isNaN(s1.getMaxY()));
}