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

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

Introduction

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

Prototype

public void setDomainCrosshairVisible(boolean flag) 

Source Link

Document

Sets the flag indicating whether or not the domain crosshair is visible and, if the flag changes, sends a PlotChangeEvent to all registered listeners.

Usage

From source file:GUI.PlotCreator.java

private ChartPanel createSeaCurrentDirectionByHPanel() {
    JFreeChart jfreechart = ChartFactory.createScatterPlot("Sea Current Direction Plot", "H",
            "Sea Current Direction", createSeaCurrentDirectionDataByH(), PlotOrientation.VERTICAL, true, true,
            false);//w  ww  .  ja  v  a  2 s  . c  o  m
    XYPlot xyPlot = (XYPlot) jfreechart.getPlot();
    xyPlot.setDomainCrosshairVisible(true);
    xyPlot.setRangeCrosshairVisible(true);
    //XYItemRenderer renderer = xyPlot.getRenderer();
    NumberAxis domain = (NumberAxis) xyPlot.getDomainAxis();
    domain.setVerticalTickLabels(true);
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesLinesVisible(0, false);
    renderer.setSeriesPaint(0, Color.blue);
    renderer.setSeriesPaint(1, Color.red);
    xyPlot.setRenderer(renderer);
    return new ChartPanel(jfreechart);
}

From source file:GUI.PlotCreator.java

private ChartPanel createEquirectangularErrorPanel(ArrayList<double[]> dataToDisplay) {
    title = "Equirectangular vs Haversine - Error Plot";
    JFreeChart jfreechart = ChartFactory.createScatterPlot(title, "Distance Between Points (meters)", "Error",
            createEquirectangularErrorData(dataToDisplay), PlotOrientation.VERTICAL, true, true, false);
    XYPlot xyPlot = (XYPlot) jfreechart.getPlot();
    xyPlot.setDomainCrosshairVisible(true);
    xyPlot.setRangeCrosshairVisible(true);
    //XYItemRenderer renderer = xyPlot.getRenderer();
    NumberAxis domain = (NumberAxis) xyPlot.getDomainAxis();
    domain.setVerticalTickLabels(true);//from w w w  . j av a 2 s .  c  o m
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesLinesVisible(0, false);
    renderer.setSeriesPaint(0, Color.blue);
    renderer.setSeriesPaint(1, Color.red);
    xyPlot.setRenderer(renderer);
    return new ChartPanel(jfreechart);
}

From source file:com.fr3ts0n.ecu.gui.application.ObdDataPlotter.java

/**
 * Creates a chart./*from  w w w  .j a va  2  s  .co  m*/
 *
 * @param dataset a dataset.
 * @return A chart.
 */
private JFreeChart createChart(XYDataset dataset) {

    chart = ChartFactory.createTimeSeriesChart("OBD Data Graph", // title
            "Time", // x-axis label
            "Value", // y-axis label
            dataset, // data
            true, // create legend?
            true, // generate tooltips?
            false // generate URLs?
    );

    chart.setBackgroundPaint(Color.white);

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);
    plot.getDomainAxis().setTickLabelFont(legendFont);

    DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("HH:mm:ss"));
    chart.getLegend().setItemFont(legendFont);

    return chart;
}

From source file:edu.psu.citeseerx.misc.charts.CiteChartBuilderJFree.java

protected JFreeChart buildChart(Document doc) throws SQLException {

    Long clusterid = doc.getClusterID();
    if (clusterid == null) {
        return null;
    }/* w w w .  j  ava  2  s .c o  m*/

    java.util.List<ThinDoc> citingDocs = citedao.getCitingDocuments(clusterid, 0, MAX_CITING);
    XYDataset dataset = collectData(citingDocs);
    if (dataset.getItemCount(0) <= 1) {
        return null;
    }

    XYBarDataset ivl_dataset = new XYBarDataset(dataset, 15.0);
    JFreeChart chart = ChartFactory.createXYBarChart(null, "Year", true, "Citation Count", ivl_dataset,
            PlotOrientation.VERTICAL, false, false, false);
    chart.setBackgroundPaint(Color.WHITE);

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.WHITE);
    plot.setRangeGridlinePaint(Color.WHITE);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    XYItemRenderer r = plot.getRenderer();

    NumberAxis axis = (NumberAxis) plot.getDomainAxis();
    axis.setNumberFormatOverride(NumberFormat.getIntegerInstance());
    //axis.setTickUnit(new DateTickUnit(DateTickUnit.YEAR, -1));
    //axis.setDateFormatOverride(new SimpleDateFormat("yyyy"));
    return chart;

}

From source file:edu.wustl.cab2b.client.ui.visualization.charts.ScatterPlot.java

protected JFreeChart createChart(Dataset dataset) {
    XYDataset xyDataset = (XYDataset) dataset;
    JFreeChart jfreechart = ChartFactory.createScatterPlot("Scatter Plot", "X", "Y", xyDataset,
            PlotOrientation.VERTICAL, true, true, false);
    jfreechart.setBackgroundPaint(Color.white);

    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    xyplot.setBackgroundPaint(Color.white);
    XYDotRenderer xydotrenderer = new XYDotRenderer();
    xydotrenderer.setDotWidth(4);//w  w w .j  a  v a 2  s. c o m
    xydotrenderer.setDotHeight(4);

    xyplot.setRenderer(xydotrenderer);
    xyplot.setDomainCrosshairVisible(true);
    xyplot.setRangeCrosshairVisible(true);

    NumberAxis numberaxis = (NumberAxis) xyplot.getDomainAxis();
    numberaxis.setAutoRangeIncludesZero(false);

    return jfreechart;
}

From source file:edu.ucla.stat.SOCR.chart.demo.CrosshairDemo4.java

/**
 * Creates a chart./*from www .  j a  v a2 s . co  m*/
 * 
 * @param dataset  the data for the chart.
 * 
 * @return a chart.
 */
protected JFreeChart createChart(XYDataset dataset) {

    JFreeChart chart = ChartFactory.createXYLineChart(chartTitle, // chart title
            domainLabel, // x axis label
            rangeLabel, // y axis label
            dataset, // data
            PlotOrientation.VERTICAL, !legendPanelOn, // include legend
            true, // tooltips
            false // urls
    );

    chart.setBackgroundPaint(Color.white);

    XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
    renderer.setBaseShapesVisible(true);
    renderer.setBaseShapesFilled(true);
    renderer.setLegendItemLabelGenerator(new SOCRXYSeriesLabelGenerator());

    // change the auto tick unit selection to integer units only...
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    setXSummary(dataset);
    return chart;

}

From source file:org.hxzon.demo.jfreechart.XYDatasetDemo2.java

private static JFreeChart createXYAreaChart(XYDataset dataset) {

    NumberAxis xAxis = new NumberAxis(xAxisLabel);
    xAxis.setAutoRangeIncludesZero(false);
    NumberAxis yAxis = new NumberAxis(yAxisLabel);
    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, null);
    plot.setOrientation(orientation);//from w  w w .jav  a  2 s .c o  m
    plot.setForegroundAlpha(0.5f);

    XYToolTipGenerator tipGenerator = null;
    if (tooltips) {
        tipGenerator = new StandardXYToolTipGenerator();
    }

    XYURLGenerator urlGenerator = null;
    if (urls) {
        urlGenerator = new StandardXYURLGenerator();
    }

    plot.setRenderer(new XYAreaRenderer(XYAreaRenderer.AREA, tipGenerator, urlGenerator));
    JFreeChart chart = new JFreeChart("XYArea Chart Demo", JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
    chart.setBackgroundPaint(Color.white);

    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    yAxis.setNumberFormatOverride(MyNumberFormat.getMyNumberFormat());

    return chart;
}

From source file:org.jfree.chart.demo.TimeSeriesDemo13.java

/**
 * Creates a chart.//from  ww w .ja  v  a 2  s.co m
 * 
 * @param dataset  a dataset.
 * 
 * @return A chart.
 */
private JFreeChart createChart(final XYDataset dataset) {

    final JFreeChart chart = ChartFactory.createTimeSeriesChart("Weekly Data", "Date", "Value", dataset, true,
            true, false);

    chart.setBackgroundPaint(Color.white);

    //        final StandardLegend sl = (StandardLegend) chart.getLegend();
    //      sl.setDisplaySeriesShapes(true);

    final XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    //    plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    final XYItemRenderer renderer = plot.getRenderer();
    if (renderer instanceof StandardXYItemRenderer) {
        final StandardXYItemRenderer rr = (StandardXYItemRenderer) renderer;
        rr.setPlotShapes(true);
        rr.setShapesFilled(true);
    }

    final DateAxis axis = (DateAxis) plot.getDomainAxis();
    final TickUnits standardUnits = new TickUnits();
    standardUnits.add(new DateTickUnit(DateTickUnit.DAY, 1, new SimpleDateFormat("MMM dd ''yy")));
    standardUnits.add(new DateTickUnit(DateTickUnit.DAY, 7, new SimpleDateFormat("MMM dd ''yy")));
    standardUnits.add(new DateTickUnit(DateTickUnit.MONTH, 1, new SimpleDateFormat("MMM ''yy")));
    axis.setStandardTickUnits(standardUnits);

    return chart;

}

From source file:org.jfree.chart.demo.CrosshairDemo1.java

/**
 * Creates a chart.// www  .j a v a 2  s.c  om
 * 
 * @param dataset  the data for the chart.
 * 
 * @return a chart.
 */
private JFreeChart createChart(final XYDataset dataset) {

    final JFreeChart chart = ChartFactory.createXYLineChart("Crosshair Demo 1", // chart title
            "X", // x axis label
            "Y", // y axis label
            dataset, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips
            false // urls
    );

    chart.setBackgroundPaint(Color.white);

    //        final StandardLegend legend = (StandardLegend) chart.getLegend();
    //      legend.setDisplaySeriesShapes(true);

    final XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.lightGray);
    //    plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    plot.setDomainCrosshairVisible(true);
    plot.setDomainCrosshairLockedOnData(true);
    plot.setRangeCrosshairVisible(true);
    plot.setRangeCrosshairLockedOnData(true);

    final StandardXYItemRenderer renderer = (StandardXYItemRenderer) plot.getRenderer();
    renderer.setPlotShapes(true);
    renderer.setShapesFilled(true);

    // change the auto tick unit selection to integer units only...
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    // OPTIONAL CUSTOMISATION COMPLETED.

    return chart;

}

From source file:org.atomserver.testutils.plot.PerfPlotter.java

/**
 *//*from w w  w.j a va 2 s  .c  o m*/
private JFreeChart createChart(XYDataset dataset) {
    JFreeChart chart = ChartFactory.createTimeSeriesChart(title, // title
            xAxisLabel, // x-axis label
            yAxisLabel, // y-axis label
            dataset, // data
            true, // create legend?
            true, // generate tooltips?
            false // generate URLs?
    );
    chart.setBackgroundPaint(Color.white);

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    if (useDataPointMarkers) {
        XYItemRenderer r = plot.getRenderer();
        if (r instanceof XYLineAndShapeRenderer) {
            XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
            renderer.setBaseShapesVisible(true);
            renderer.setBaseShapesFilled(true);
        }
    }

    DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("HH:mm:ss"));

    return chart;
}