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

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

Introduction

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

Prototype

public void setDomainCrosshairValue(double value) 

Source Link

Document

Sets the domain crosshair value and sends a PlotChangeEvent to all registered listeners (provided that the domain crosshair is visible).

Usage

From source file:cgpanalyser.gui.chart.ChartCreator.java

/**
 * Sets value of crosshair to first item in chart.
 *
 * @param jfreechart/*w  ww  . ja  v  a  2  s  . c o m*/
 */
private void setCrosshairDefaultValue(XYPlot plot, XYDataset dataset) {
    if (dataset.getItemCount(0) != 0) {
        plot.setDomainCrosshairValue(dataset.getXValue(0, 0));
        plot.setRangeCrosshairValue(dataset.getYValue(0, 0));
    }
}

From source file:org.webcat.grader.graphs.HistogramChart.java

protected JFreeChart generateChart(WCChartTheme chartTheme) {
    JFreeChart chart = ChartFactory.createHistogram(null, xAxisLabel(), yAxisLabel(), intervalXYDataset(),
            orientation(), false, false, false);

    XYPlot plot = chart.getXYPlot();
    XYBarRenderer renderer = (XYBarRenderer) plot.getRenderer();
    renderer.setAutoPopulateSeriesOutlinePaint(true);
    renderer.setDrawBarOutline(true);//from ww  w  .ja v  a  2  s  .  c  om
    renderer.setShadowVisible(false);

    if (markValue != null) {
        plot.setDomainCrosshairVisible(true);
        plot.setDomainCrosshairValue(markValue.doubleValue());
        plot.setDomainCrosshairPaint(Color.red);
        plot.setDomainCrosshairStroke(MARKER_STROKE);
    }

    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    return chart;
}

From source file:org.lmn.fc.frameworks.starbase.plugins.observatory.ui.tabs.charts.ChartUIHelper.java

/***********************************************************************************************
 * Calculate and update the Domain Offset Crosshair and draw the crosshair on the XYPlot.
 * Return the value set on the XYPlot, or Double.MIN_VALUE on failure.
 *
 * @param chartui// w ww  .ja va 2  s .c  om
 * @param valueminimum
 * @param valuemaximum
 * @param offset
 * @param debug
 *
 * @return double
 */

public static double updateDomainCrosshairForOffsetControl(final ChartUIComponentPlugin chartui,
        final int valueminimum, final int valuemaximum, final double offset, final boolean debug) {
    final String SOURCE = "ChartHelper.updateDomainCrosshairForOffsetControl() ";
    double dblDomainCrosshairXYPlot;

    dblDomainCrosshairXYPlot = Double.MIN_VALUE;

    if (chartui != null) {
        if ((chartui.getChartPanel() != null) && (chartui.getChartPanel().getChart() != null)
                && (chartui.getChartPanel().getChart().getPlot() != null)) {
            final XYPlot plot;
            final ValueAxis domainAxis;
            final Range range;
            final double dblPositionFraction;

            //  Save the supplied new value
            chartui.setDomainCrosshair(offset);

            plot = (XYPlot) chartui.getChartPanel().getChart().getPlot();
            domainAxis = plot.getDomainAxis();
            range = domainAxis.getRange();

            if (offset >= 0) {
                //dblPositionFraction = (offset - (double)valueminimum) / (double)(valuemaximum - valueminimum);
                dblPositionFraction = (offset * 2.0) / (double) (valuemaximum - valueminimum);
            } else {
                dblPositionFraction = 0.0;
            }

            dblDomainCrosshairXYPlot = domainAxis.getLowerBound() + (dblPositionFraction * range.getLength());

            // Update the XYPlot
            plot.setDomainCrosshairValue(dblDomainCrosshairXYPlot);

            FrameworkSingletons.LOGGER.debug(debug,
                    SOURCE + "Domain Crosshair updated [value.knob=" + offset + "] [value.xyplot="
                            + dblDomainCrosshairXYPlot + "] [domain.lowerbound=" + domainAxis.getLowerBound()
                            + "] [domain.upperbound=" + domainAxis.getUpperBound() + "] [value.fraction="
                            + dblPositionFraction + "] [value.minimum=" + valueminimum + "] [value.maximum="
                            + valuemaximum + "]");
        } else {
            FrameworkSingletons.LOGGER.debug(debug,
                    SOURCE + "There is no Chart, so cannot update Domain Crosshair on XYPlot");

            // Save a default value
            chartui.setDomainCrosshair(valueminimum);

            dblDomainCrosshairXYPlot = Double.MIN_VALUE;
        }
    }

    return (dblDomainCrosshairXYPlot);
}

From source file:cgpanalyser.gui.chart.XYChartPanel.java

public void setNextCrosshairValue(JFreeChart jfreechart) {
    XYPlot plot = (XYPlot) jfreechart.getPlot();
    XYDataset dataset = plot.getDataset();

    //set crosshair to next value if not on last already
    for (int i = 0; i < dataSampler.getLastToDisplay().size() - 1; i++) { //find generation in datasampler.todisplay
        if ((int) plot.getDomainCrosshairValue() == dataSampler.getLastToDisplay().get(i).getGenNumber()) {
            plot.setDomainCrosshairValue(dataset.getXValue(0, i + 1));
            plot.setRangeCrosshairValue(dataset.getYValue(0, i + 1));
            break;
        }/*from w  w  w  .  j  a v  a  2 s  . c o  m*/
    }

}

From source file:cgpanalyser.gui.chart.XYChartPanel.java

public void setPrevCrosshairValue(JFreeChart jfreechart) {
    XYPlot plot = (XYPlot) jfreechart.getPlot();
    XYDataset dataset = plot.getDataset();

    //set crosshair to previous value if not on first already
    for (int i = 0; i < dataSampler.getLastToDisplay().size(); i++) { //find generation in datasampler.todisplay
        if ((int) plot.getDomainCrosshairValue() == dataSampler.getLastToDisplay().get(i).getGenNumber()) {
            if (i > 0) {
                plot.setDomainCrosshairValue(dataset.getXValue(0, i - 1));
                plot.setRangeCrosshairValue(dataset.getYValue(0, i - 1));
            }// w w w  . ja v  a2  s. c om
            break;
        }
    }

}

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

@Override
public void stateChanged(ChangeEvent e) {
    int value = this.slider.getValue();
    XYPlot plot = (XYPlot) this.getChart().getPlot();

    ValueAxis domainAxis = plot.getDomainAxis();
    Range range = domainAxis.getRange();
    double c = domainAxis.getLowerBound() + (value / 100.0) * range.getLength();

    // displays the vertical crosshair in the desired position
    plot.setDomainCrosshairValue(c);

    // the cross hair is keyed to the horizontal slider - for the time domain axis
    setCrossHairDomainIndex();/*  ww  w  .ja v a  2  s  . com*/
}

From source file:org.lmn.fc.frameworks.starbase.plugins.observatory.ui.tabs.charts.GpsScatterPlotUIComponent.java

/***********************************************************************************************
 * Update the Centroid Crosshairs, provided that ObservatoryMetadata contains valid
 * Observation.Centroid.Longitude and Observation.Centroid.Latitude.
 *//*from w w  w  .j av a2 s  .c  om*/

private void updateCentroidCrosshairs() {
    final String SOURCE = "GpsScatterPlotUIComponent.updateCentroidCrosshairs() ";

    if ((getHostInstrument() != null) && (getHostInstrument().getDAO() != null)
            && (getHostInstrument().getDAO().getChartUI() != null)
            && (getHostInstrument().getDAO().getChartUI().getChartPanel() != null)
            && (getHostInstrument().getDAO().getChartUI().getChartPanel().getChart() != null)
            && (getHostInstrument().getDAO().getObservationMetadata() != null)) {
        final Metadata metadataLongitude;
        final Metadata metadataLatitude;
        DegMinSecInterface dmsCentroidLongitude;
        DegMinSecInterface dmsCentroidLatitude;
        final List<String> errors;

        dmsCentroidLongitude = null;
        dmsCentroidLatitude = null;
        errors = new ArrayList<String>(10);

        // Get the centroid of the fixes from the Observation Metadata
        metadataLongitude = MetadataHelper.getMetadataByKey(
                getHostInstrument().getDAO().getObservationMetadata(),
                MetadataDictionary.KEY_OBSERVATION_CENTROID_LONGITUDE.getKey());
        metadataLatitude = MetadataHelper.getMetadataByKey(
                getHostInstrument().getDAO().getObservationMetadata(),
                MetadataDictionary.KEY_OBSERVATION_CENTROID_LATITUDE.getKey());

        if (metadataLongitude != null) {
            dmsCentroidLongitude = (DegMinSecInterface) DataTypeHelper.parseDataTypeFromValueField(
                    metadataLongitude.getValue(), DataTypeDictionary.SIGNED_LONGITUDE, EMPTY_STRING,
                    EMPTY_STRING, errors);
        }

        if (metadataLatitude != null) {
            dmsCentroidLatitude = (DegMinSecInterface) DataTypeHelper.parseDataTypeFromValueField(
                    metadataLatitude.getValue(), DataTypeDictionary.LATITUDE, EMPTY_STRING, EMPTY_STRING,
                    errors);
        }

        if ((errors.isEmpty()) && (dmsCentroidLongitude != null) && (dmsCentroidLatitude != null)) {
            final XYPlot plot;

            plot = (XYPlot) getHostInstrument().getDAO().getChartUI().getChartPanel().getChart().getPlot();

            if (plot != null) {
                // Remember that the Domain is the X-axis, i.e. Longitude
                plot.setDomainCrosshairValue(dmsCentroidLongitude.toDouble());
                plot.setRangeCrosshairValue(dmsCentroidLatitude.toDouble());
            }
        }

        LOGGER.errors(SOURCE, errors);
    }
}

From source file:org.gbif.portal.web.controller.dataset.IndexingHistoryController.java

/**
 * Create a time series graphic to display indexing processes.
 * //from   w  w w .  ja v  a  2  s.  c  om
 * @param dataProvider
 * @param dataResource
 * @param activities
 * @param fileNamePrefix
 * @return
 */
public String timeSeriesTest(DataProviderDTO dataProvider, DataResourceDTO dataResource,
        List<LoggedActivityDTO> loggedActivities, String fileNamePrefix, int minProcessingTimeToRender) {

    List<LoggedActivityDTO> activities = new ArrayList<LoggedActivityDTO>();
    for (LoggedActivityDTO la : loggedActivities) {
        if (la.getDataResourceKey() != null && la.getDataResourceName() != null && la.getEventName() != null)
            activities.add(la);
    }

    //if no activities to render, return
    if (activities.isEmpty())
        return null;

    Map<String, Integer> drActualCount = new HashMap<String, Integer>();
    Map<String, Integer> drCount = new HashMap<String, Integer>();

    //record the actual counts
    for (LoggedActivityDTO laDTO : activities) {
        if (laDTO.getStartDate() != null && laDTO.getEndDate() != null
                && laDTO.getDurationInMillisecs() > minProcessingTimeToRender) {
            if (drActualCount.get(laDTO.getDataResourceName()) == null) {
                drActualCount.put(laDTO.getDataResourceName(), new Integer(4));
                drCount.put(laDTO.getDataResourceName(), new Integer(0));
            } else {
                Integer theCount = drActualCount.get(laDTO.getDataResourceName());
                theCount = new Integer(theCount.intValue() + 4);
                drActualCount.remove(laDTO.getDataResourceName());
                drActualCount.put(laDTO.getDataResourceName(), theCount);
            }
        }
    }

    StringBuffer fileNameBuffer = new StringBuffer(fileNamePrefix);
    if (dataResource != null) {
        fileNameBuffer.append("-resource-");
        fileNameBuffer.append(dataResource.getKey());
    } else if (dataProvider != null) {
        fileNameBuffer.append("-provider-");
        fileNameBuffer.append(dataProvider.getKey());
    }
    fileNameBuffer.append(".png");

    String fileName = fileNameBuffer.toString();
    String filePath = System.getProperty("java.io.tmpdir") + File.separator + fileName;

    File fileToCheck = new File(filePath);
    if (fileToCheck.exists()) {
        return fileName;
    }

    TimeSeriesCollection dataset = new TimeSeriesCollection();
    boolean generateChart = false;

    int count = 1;
    int dataResourceCount = 1;

    Collections.sort(activities, new Comparator<LoggedActivityDTO>() {
        public int compare(LoggedActivityDTO o1, LoggedActivityDTO o2) {
            if (o1 == null || o2 == null || o1.getDataResourceKey() != null || o2.getDataResourceKey() != null)
                return -1;
            return o1.getDataResourceKey().compareTo(o2.getDataResourceKey());
        }
    });

    String currentDataResourceKey = activities.get(0).getDataResourceKey();

    for (LoggedActivityDTO laDTO : activities) {
        if (laDTO.getStartDate() != null && laDTO.getEndDate() != null
                && laDTO.getDurationInMillisecs() > minProcessingTimeToRender) {

            if (currentDataResourceKey != null && !currentDataResourceKey.equals(laDTO.getDataResourceKey())) {
                dataResourceCount++;
                count = count + 1;
                currentDataResourceKey = laDTO.getDataResourceKey();
            }
            TimeSeries s1 = new TimeSeries(laDTO.getDataResourceName(), "Process time period",
                    laDTO.getEventName(), Hour.class);
            s1.add(new Hour(laDTO.getStartDate()), count);
            s1.add(new Hour(laDTO.getEndDate()), count);
            dataset.addSeries(s1);
            generateChart = true;
        }
    }

    if (!generateChart)
        return null;

    // create a pie chart...
    final JFreeChart chart = ChartFactory.createTimeSeriesChart(null, null, null, dataset, false, false, false);

    XYPlot plot = chart.getXYPlot();
    plot.setWeight(10);
    plot.getRangeAxis().setAutoRange(false);
    plot.getRangeAxis().setRange(0, drCount.size() + 1);
    plot.getRangeAxis().setAxisLineVisible(false);
    plot.getRangeAxis().setAxisLinePaint(Color.WHITE);
    plot.setDomainCrosshairValue(1);
    plot.setRangeGridlinesVisible(false);
    plot.getRangeAxis().setVisible(false);
    plot.getRangeAxis().setLabel("datasets");

    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
    renderer.setItemLabelsVisible(true);
    MyXYItemLabelGenerator labelGenerator = new MyXYItemLabelGenerator();
    labelGenerator.setDataResourceActualCount(drActualCount);
    labelGenerator.setDataResourceCount(drCount);
    renderer.setItemLabelGenerator(labelGenerator);

    List<TimeSeries> seriesList = dataset.getSeries();
    for (TimeSeries series : seriesList) {
        if (((String) series.getRangeDescription()).startsWith("extraction")) {
            renderer.setSeriesPaint(seriesList.indexOf(series), Color.RED);
        } else {
            renderer.setSeriesPaint(seriesList.indexOf(series), Color.BLUE);
        }
        renderer.setSeriesStroke(seriesList.indexOf(series), new BasicStroke(7f));
    }

    int imageHeight = 30 * dataResourceCount;
    if (imageHeight < 100) {
        imageHeight = 100;
    } else {
        imageHeight = imageHeight + 100;
    }

    final BufferedImage image = new BufferedImage(900, imageHeight, BufferedImage.TYPE_INT_RGB);
    KeypointPNGEncoderAdapter adapter = new KeypointPNGEncoderAdapter();
    adapter.setQuality(1);
    try {
        adapter.encode(image);
    } catch (IOException e) {
        logger.error(e.getMessage(), e);
    }
    final Graphics2D g2 = image.createGraphics();
    g2.setFont(new Font("Arial", Font.PLAIN, 11));
    final Rectangle2D chartArea = new Rectangle2D.Double(0, 0, 900, imageHeight);

    // draw
    chart.draw(g2, chartArea, null, null);

    //styling
    chart.setPadding(new RectangleInsets(0, 0, 0, 0));
    chart.setBorderVisible(false);
    chart.setBackgroundImageAlpha(0);
    chart.setBackgroundPaint(Color.WHITE);
    chart.setBorderPaint(Color.LIGHT_GRAY);

    try {
        FileOutputStream fOut = new FileOutputStream(filePath);
        ChartUtilities.writeChartAsPNG(fOut, chart, 900, imageHeight);
        return fileName;
    } catch (IOException e) {
        logger.error(e.getMessage(), e);
    }
    return null;
}

From source file:ec.util.chart.swing.JTimeSeriesChart.java

private void onCrosshairValueChange(ObsIndex value) {
    if (isElementVisible(Element.CROSSHAIR) && existPredicate.apply(value)) {
        double x = dataset.getXValue(value.getSeries(), value.getObs());
        double y = dataset.getYValue(value.getSeries(), value.getObs());
        int index = plotDispatcher.apply(value.getSeries());
        for (XYPlot subPlot : roSubPlots) {
            subPlot.setDomainCrosshairValue(x);
            subPlot.setDomainCrosshairVisible(crosshairOrientation != CrosshairOrientation.HORIZONTAL);
            if (roSubPlots.indexOf(subPlot) == index && crosshairOrientation != CrosshairOrientation.VERTICAL) {
                subPlot.setRangeCrosshairValue(y);
                subPlot.setRangeCrosshairVisible(true);
            } else {
                subPlot.setRangeCrosshairVisible(false);
            }/*from www .j  a  v  a  2 s  .  co m*/
        }
    } else {
        for (XYPlot subPlot : roSubPlots) {
            subPlot.setRangeCrosshairVisible(false);
            subPlot.setDomainCrosshairVisible(false);
        }
    }
}

From source file:com.att.aro.ui.view.diagnostictab.GraphPanel.java

private void setCrossHair(double crossHairValue) {
    // set the cross hair values of plot and sub-plots
    Plot mainplot = getAdvancedGraph().getPlot();
    if (mainplot instanceof CombinedDomainXYPlot) {
        combinedPlot = (CombinedDomainXYPlot) mainplot;
        List<?> plots = combinedPlot.getSubplots();
        for (Object p : plots) {
            if (p instanceof XYPlot) {
                XYPlot subPlot = (XYPlot) p;
                subPlot.setDomainCrosshairLockedOnData(false);
                subPlot.setDomainCrosshairValue(crossHairValue);
                subPlot.setDomainCrosshairVisible(true);
            }//from w ww. j  a  v a  2s  . c o m
        }
        combinedPlot.setDomainCrosshairLockedOnData(false);
        combinedPlot.setDomainCrosshairValue(crossHairValue, true);
        combinedPlot.setDomainCrosshairVisible(true);
    }
    getHandlePanel().setHandlePosition(getHandleCoordinate());

}