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

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

Introduction

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

Prototype

public XYDataset getDataset() 

Source Link

Document

Returns the primary dataset for the plot.

Usage

From source file:dbseer.gui.events.InformationChartMouseListener.java

@Override
public void chartMouseClicked(ChartMouseEvent event) {
    Rectangle2D dataArea = chartPanel.getScreenDataArea();
    JFreeChart chart = event.getChart();
    XYPlot plot = (XYPlot) chart.getPlot();
    ValueAxis xAxis = plot.getDomainAxis();
    int x = (int) Math.round(xAxis.java2DToValue(event.getTrigger().getX(), dataArea, RectangleEdge.BOTTOM));

    XYDataset dataset = plot.getDataset();
    int maxX = DatasetUtilities.findMaximumDomainValue(dataset).intValue();
    if (x >= 1 && x <= maxX) {
        int seriesCount = dataset.getSeriesCount();
        int[] mixtures = new int[seriesCount - 1];
        int total = 0;
        for (int i = 0; i < seriesCount - 1; ++i) {
            mixtures[i] = (int) dataset.getYValue(i, x - 1);
            total += mixtures[i];/*  ww w.  j  a  va 2  s  .  co  m*/
        }
        for (int i = 0; i < seriesCount - 1; ++i) {
            mixtures[i] = (int) Math.round((double) mixtures[i] / (double) total * 100.0);
            tpsMixturePanel.setMixture(i, mixtures[i]);
        }
    }
}

From source file:org.operamasks.faces.render.graph.CompositeChartRenderer.java

private JFreeChart createXYCompositeChart(List<JFreeChart> subcharts, UIChart comp) {
    XYPlot compositePlot = new XYPlot();
    compositePlot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
    compositePlot.setOrientation(getChartOrientation(comp));

    for (int i = 0; i < subcharts.size(); i++) {
        XYPlot subplot = (XYPlot) subcharts.get(i).getPlot();
        compositePlot.setDataset(i, subplot.getDataset());
        compositePlot.setRenderer(i, subplot.getRenderer());

        if (i == 0) {
            compositePlot.setDomainAxis(0, subplot.getDomainAxis());
            compositePlot.setRangeAxis(0, subplot.getRangeAxis());
        } else {//from w w w .  j  ava  2 s  . c  om
            int yAxisMap = getRangeAxisMap(comp, i);
            ValueAxis yAxis = null;
            if (yAxisMap == -1) {
                yAxisMap = 0; // map to axis zero by default
            } else if (yAxisMap == i) {
                yAxis = subplot.getRangeAxis(); // add subplot axis to composite plot
            }
            compositePlot.setRangeAxis(i, yAxis);
            compositePlot.mapDatasetToRangeAxis(i, yAxisMap);
        }
    }

    return new JFreeChart(null, null, compositePlot, false);
}

From source file:org.fhcrc.cpl.toolbox.gui.chart.PanelWithChart.java

protected void saveChartDataToFile(File outFile, String delimiter) {
    _log.debug("saveChartDataToFile1, *delimiter*=*" + delimiter + "*");
    XYPlot xyPlot = (XYPlot) _plot;
    XYDataset dataset = xyPlot.getDataset();

    boolean hasZValues = false;
    if (dataset instanceof XYZDataset)
        hasZValues = true;/*from w  w w .j av a  2 s  . c  om*/

    PrintWriter pw = null;

    try {
        pw = new PrintWriter(outFile);
        int seriesCount = dataset.getSeriesCount();
        String headerLine = null;

        if (seriesCount > 1)
            headerLine = "series" + delimiter + "x" + delimiter + "y";
        else
            headerLine = "x" + delimiter + "y";
        if (hasZValues)
            headerLine = headerLine + delimiter + "z";

        pw.println(headerLine);

        for (int i = 0; i < seriesCount; i++) {
            int itemCount = dataset.getItemCount(i);
            for (int j = 0; j < itemCount; j++) {
                String fileLine = null;
                if (seriesCount > 1)
                    fileLine = i + delimiter + dataset.getX(i, j) + delimiter + dataset.getY(i, j);
                else
                    fileLine = dataset.getX(i, j) + delimiter + dataset.getY(i, j);

                if (hasZValues)
                    fileLine = fileLine + delimiter + ((XYZDataset) dataset).getZ(i, j);
                pw.println(fileLine);
            }
            pw.flush();
        }
    } catch (Exception e) {
        ApplicationContext.errorMessage(TextProvider.getText("ERROR_SAVING_CHART_DATA"), e);
    } finally {
        if (pw != null)
            pw.close();
    }
}

From source file:gov.llnl.lc.infiniband.opensm.plugin.gui.chart.AdvancedXY_PlotPanel.java

/**
 * Sets the value of crossHairDomainIndex
 *
 * @param crossHairDomainIndex the crossHairDomainIndex to set
 *
 ***********************************************************/
protected void setCrossHairDomainIndex() {
    int value = this.slider.getValue();

    if (this.chartPanel != null) {
        JFreeChart c = this.getChart();
        this.getChart();
        if (c != null) {
            XYPlot plot = (XYPlot) c.getPlot();
            XYDataset dataset = plot.getDataset();
            int itemCount = dataset.getItemCount(0);
            double ndexD = (double) itemCount * ((double) value / 100);
            int ndex = (int) ndexD;

            // the index goes from 0 to (itemCount -1)
            this.CrossHairDomainIndex = ndex >= itemCount ? itemCount - 1 : ndex;
        }/*from   w  w  w.  j a v  a 2s . co m*/
    }
}

From source file:lifnetwork.ChartSave.java

public ChartSave() {
    super(ChartFactory.createScatterPlot("Population Fire", "Time (s)", "Neuron #", (new XYSeriesCollection()),
            PlotOrientation.VERTICAL, false, false, false));
    fireChart = this.getChart();
    fireChart.setNotify(false);/*from   w  w  w.j a v  a2  s .com*/
    XYPlot plot = fireChart.getXYPlot();
    plot.setBackgroundPaint(Color.WHITE);
    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
    renderer.setSeriesShapesVisible(0, true);
    renderer.setSeriesShape(0, new Rectangle2D.Double(0, 0, 1, 1));
    fireCollection = (XYSeriesCollection) plot.getDataset();
    fireSeries = new XYSeries("fires");
    fireCollection.addSeries(fireSeries);
}

From source file:net.sf.maltcms.chromaui.charts.overlay.Peak2DOverlay.java

/**
 *
 * @param g2/*from   ww  w. j  a v a2 s.  c  o  m*/
 * @param chartPanel
 */
@Override
public void paintOverlay(Graphics2D g2, ChartPanel chartPanel) {
    if (isVisible()) {
        JFreeChart chart = chartPanel.getChart();
        XYPlot plot = (XYPlot) chart.getPlot();
        if (plot.getDataset() instanceof Chromatogram2DDataset) {
            dataset = (ADataset2D<IChromatogram2D, IScan2D>) plot.getDataset();
        } else {
            throw new IllegalArgumentException("Unsupported dataset type: " + plot.getDataset().getClass());
        }
        if (shapes == null) {
            shapes = renderer.generatePeak2DShapes(peakAnnotations, dataset, non2DPeaks);
        } else {
            XYDataset xyds = plot.getDataset();
            if (xyds != dataset || drawOutlines) {
                shapes = renderer.generatePeak2DShapes(peakAnnotations, dataset, non2DPeaks);
            }
        }
        Color fillColor = peakAnnotations.getColor();
        if (fillColor == null || fillColor.equals(Color.WHITE)
                || fillColor.equals(new Color(255, 255, 255, 0))) {
            Logger.getLogger(getClass().getName())
                    .fine("Peak annotation color was null or white, using color from treatment group!");
            fillColor = peakAnnotations.getChromatogram().getTreatmentGroup().getColor();
        }
        if (isVisible()) {
            renderer.draw(g2, chartPanel, plot, fillColor, shapes, selectedPeaks);
        }
    }
}

From source file:org.trade.ui.chart.renderer.CandleRenderer.java

/**
 * Method highlight.//from  www. j a v a2  s  .c  o m
 * 
 * @param row
 *            int
 * @param column
 *            int
 * @return boolean
 */
public boolean highlight(int row, int column) {
    XYPlot plot = getPlot();
    OHLCDataset highLowData = (OHLCDataset) plot.getDataset();
    int total_elements = highLowData.getItemCount(0);
    boolean isLast = column == (total_elements - 1);
    if (isLast) {
        return true;
    }
    return false;
}

From source file:MWC.GUI.JFreeChart.ColourStandardXYItemRenderer.java

/**
 * Returns a legend item for a series.//from  w  w  w  . j  av  a  2 s  . c o  m
 * 
 * @param series
 *          the series (zero-based index).
 * 
 * @return a legend item for the series.
 */
public LegendItem getLegendItem(final int series) {

    final XYPlot plot = this.getPlot();

    final XYDataset dataset = plot.getDataset();
    final String label = (String) dataset.getSeriesKey(series);
    final String description = label;
    final Shape shape = null;
    final Paint paint = this.getSeriesPaint(series);
    final Paint outlinePaint = paint;
    final Stroke stroke = plot.getRenderer().getSeriesStroke(series);

    return new LegendItem(label, description, null, null, shape, paint, stroke, outlinePaint);
}

From source file:net.sf.maltcms.chromaui.foldChangeViewer.ui.panel.FoldChangeViewPanel.java

public void setPlot(final XYPlot plot) {
    removeAxisListener();/*from  w  w w  . ja  va 2  s  . co  m*/
    ADataset1D<?, FoldChangeElement> dataset = null;
    if (plot.getDataset() instanceof ADataset1D) {
        dataset = (ADataset1D<?, FoldChangeElement>) plot.getDataset();
    } else {
        throw new IllegalArgumentException("Requires a plot with ADataset1D!");
    }
    this.plot = plot;
    if (selectionOverlay != null) {
        content.remove(selectionOverlay);
        selectionOverlay = null;
    }
    if (selectionOverlay == null) {
        selectionOverlay = new SelectionOverlay(Color.BLUE, Color.RED, 1.75f, 1.75f, 0.66f);
        chartPanel.addOverlay(selectionOverlay);
        selectionOverlay.addChangeListener(chartPanel);
        content.add(selectionOverlay);
    } else {
        for (ISelection selection : selectionOverlay.getMouseClickSelection()) {
            selection.setDataset(dataset);
        }

        ISelection selection = selectionOverlay.getMouseHoverSelection();
        if (selection != null) {
            selection.setDataset(dataset);
        }
    }
    if (selectionHandler == null) {
        selectionHandler = new InstanceContentSelectionHandler(this.content, selectionOverlay,
                InstanceContentSelectionHandler.Mode.ON_CLICK, dataset, 1);
    } else {
        selectionHandler.setDataset(dataset);
    }
    if (mouseSelectionHandler == null) {
        mouseSelectionHandler = new XYMouseSelectionHandler<FoldChangeElement>(dataset);
        mouseSelectionHandler.addSelectionChangeListener(selectionOverlay);
        mouseSelectionHandler.addSelectionChangeListener(selectionHandler);
        chartPanel.addChartMouseListener(mouseSelectionHandler);
    } else {
        mouseSelectionHandler.setDataset(dataset);
    }

    AxisChangeListener listener = selectionOverlay;
    ValueAxis domain = this.plot.getDomainAxis();
    ValueAxis range = this.plot.getRangeAxis();
    if (domain != null) {
        domain.addChangeListener(listener);
    }
    if (range != null) {
        range.addChangeListener(listener);
    }

    if (dataset == null || dataset.getSeriesCount() == 0) {
        this.plot.setNoDataMessage("<No Data Available>");
    } else {
        this.plot.setNoDataMessage("Loading Data...");
    }
    this.plot.setDomainPannable(true);
    this.plot.setRangePannable(true);
    chart = new JFreeChart(this.plot);
    chartPanel.setChart(chart);
    XYItemRenderer r = this.plot.getRenderer();
    if (r instanceof XYLineAndShapeRenderer) {
        ((XYLineAndShapeRenderer) r).setDrawSeriesLineAsPath(false);
        ((XYLineAndShapeRenderer) r).setBaseShapesVisible(true);
        ((XYLineAndShapeRenderer) r).setBaseShapesFilled(true);
    } else if (r instanceof XYAreaRenderer) {
        ((XYAreaRenderer) r).setOutline(true);
    }
    ChartCustomizer.setSeriesColors(this.plot, 0.8f);
    ChartCustomizer.setSeriesStrokes(this.plot, 2.0f);
    dmkl = new DomainMarkerKeyListener(this.plot);
    dmkl.setPlot(this.plot);
    chartPanel.addKeyListener(dmkl);
    addAxisListener();
    //add available chart overlays
    List<Overlay> overlays = new ArrayList<Overlay>(getLookup().lookupAll(Overlay.class));
    Collections.sort(overlays, new Comparator<Overlay>() {

        @Override
        public int compare(Overlay o1, Overlay o2) {
            if (o1 instanceof ChartOverlay && o2 instanceof ChartOverlay) {
                ChartOverlay co1 = (ChartOverlay) o1;
                ChartOverlay co2 = (ChartOverlay) o2;
                return Integer.compare(co1.getLayerPosition(), co2.getLayerPosition());
            } else {
                return 0;
            }
        }
    });
    for (Overlay overlay : overlays) {
        if (!(overlay instanceof SelectionOverlay)) {
            chartPanel.removeOverlay(overlay);
            if (overlay instanceof AxisChangeListener) {
                AxisChangeListener axisChangeListener = (AxisChangeListener) overlay;
                if (domain != null) {
                    domain.addChangeListener(axisChangeListener);
                }
                if (range != null) {
                    range.addChangeListener(axisChangeListener);
                }
            }
            if (overlay instanceof ISelectionChangeListener) {
                ISelectionChangeListener isl = (ISelectionChangeListener) overlay;
                mouseSelectionHandler.addSelectionChangeListener(isl);
                mouseSelectionHandler.addSelectionChangeListener(selectionHandler);
                selectionOverlay.addChangeListener(chartPanel);
            }
            chartPanel.addOverlay(overlay);
            overlay.addChangeListener(chartPanel);
        }
    }
    //add selection overlay last
    chartPanel.removeOverlay(selectionOverlay);
    chartPanel.addOverlay(selectionOverlay);
}

From source file:net.sf.maltcms.chromaui.charts.overlay.Peak1DOverlay.java

/**
 *
 * @param g2/*w  w  w  . j  a va 2  s  .co  m*/
 * @param chartPanel
 */
@Override
public void paintOverlay(Graphics2D g2, ChartPanel chartPanel) {
    JFreeChart chart = chartPanel.getChart();
    XYPlot plot = (XYPlot) chart.getPlot();
    ADataset1D<IChromatogram1D, IScan> newDataset;
    if (plot.getDataset() instanceof EIC1DDataset || plot.getDataset() instanceof Chromatogram1DDataset
            || plot.getDataset() instanceof TopViewDataset) {
        newDataset = (ADataset1D<IChromatogram1D, IScan>) plot.getDataset();
    } else {
        throw new IllegalArgumentException("Unsupported dataset type: " + plot.getDataset().getClass());
    }
    Color fillColor = peakAnnotations.getColor();
    if (fillColor == null || fillColor.equals(Color.WHITE) || fillColor.equals(new Color(255, 255, 255, 0))) {
        fillColor = peakAnnotations.getChromatogram().getTreatmentGroup().getColor();
    }
    if (shapes == null) {
        shapes = renderer.generatePeakShapes(peakAnnotations, newDataset);
        this.dataset = newDataset;
    } else {
        XYDataset xyds = plot.getDataset();
        if (xyds != dataset || drawOutlines) {
            shapes = renderer.generatePeakShapes(peakAnnotations, newDataset);
            this.dataset = newDataset;
        }
    }
    if (isVisible()) {
        renderer.draw(g2, chartPanel, plot, fillColor, shapes, selectedPeaks);
    }
}