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, boolean notify) 

Source Link

Document

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

Usage

From source file:org.fhaes.fhsamplesize.view.SSIZCurveChart.java

/**
 * Create the chart./*from   w w  w .j  av a2s . co m*/
 * 
 * @param eventsPerCenturyDataset
 * @return
 */
private static JFreeChart createChart(final XYDataset eventsPerCenturyDataset, Integer xcross, Integer ycross) {

    // JFreeChart jfreechart = ChartFactory.createTimeSeriesChart(null, "Number of series resampled", "Number of events",
    // eventsPerCenturyDataset, true, true, false);

    JFreeChart jfreechart = ChartFactory.createScatterPlot(null, "Number of series resampled",
            "Number of events per century", eventsPerCenturyDataset);

    jfreechart.setBackgroundPaint(Color.WHITE);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    xyplot.setInsets(new RectangleInsets(5D, 5D, 5D, 20D));
    xyplot.setBackgroundPaint(Color.WHITE);
    xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D));
    // xyplot.setDomainGridlinePaint(Color.white);
    // xyplot.setRangeGridlinePaint(Color.white);
    DeviationRenderer deviationrenderer = new DeviationRenderer(true, false);
    deviationrenderer.setSeriesStroke(0, new BasicStroke(3F, 1, 1));
    deviationrenderer.setSeriesStroke(0, new BasicStroke(3F, 1, 1));
    deviationrenderer.setSeriesStroke(1, new BasicStroke(3F, 1, 1));
    deviationrenderer.setSeriesFillPaint(0, new Color(255, 200, 200));
    deviationrenderer.setSeriesFillPaint(1, new Color(200, 200, 255));
    xyplot.setRenderer(deviationrenderer);
    NumberAxis numberaxis = (NumberAxis) xyplot.getRangeAxis();
    numberaxis.setAutoRangeIncludesZero(false);
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    jfreechart.removeLegend();

    if (xcross != null && ycross != null) {
        XYPlot xyp = jfreechart.getXYPlot();

        xyp.setRangeCrosshairVisible(true);
        xyp.setRangeCrosshairValue(ycross, true);
        xyp.setRangeCrosshairLockedOnData(true);

        xyp.setDomainCrosshairVisible(true);
        xyp.setDomainCrosshairValue(xcross, true);
        xyp.setDomainCrosshairLockedOnData(true);
    }

    // Initialize the chart variable for later use
    chart = jfreechart;

    return jfreechart;
}