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:org.n52.oxf.render.sos.TimeSeriesChartRenderer.java

/**
 * /*from   w w w . ja va  2s.c  om*/
 * @param dataset
 * @param width
 * @param height
 * @return
 */
private JFreeChart drawChart(XYDataset dataset) {

    JFreeChart chart = ChartFactory.createTimeSeriesChart(null, // title
            "Date", // x-axis label
            phenomenon, // 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.white);
    plot.setDomainGridlinePaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.lightGray);
    plot.setAxisOffset(new RectangleInsets(2.0, 2.0, 2.0, 2.0));
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    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());

    return chart;
}

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

protected JFreeChart createChart(XYDataset dataset) {

    JFreeChart c = ChartFactory.createTimeSeriesChart(chartTitle, // "Legal & General Unit Trust Prices",
            domainLabel, rangeLabel, // "Date", "Price Per Unit",
            dataset, !legendPanelOn, true, false);

    c.setBackgroundPaint(Color.white);

    XYPlot plot = (XYPlot) c.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 renderer = plot.getRenderer();
    if (renderer instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer rr = (XYLineAndShapeRenderer) renderer;
        rr.setBaseShapesVisible(true);/*w w  w .  j a v  a2s  . com*/
        rr.setBaseShapesFilled(true);
    }
    renderer.setLegendItemLabelGenerator(new SOCRXYSeriesLabelGenerator());

    DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy"));

    //setXSummary(dataset) X is time;
    return c;

}

From source file:org.rioproject.examples.hospital.ui.PatientStatsPanel.java

private JFreeChart createTimeSeriesChart(TimeSeriesCollection dataSet, Color color) {
    JFreeChart chart = ChartFactory.createTimeSeriesChart("", "", "", dataSet, true, true, false);

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.getRenderer().setSeriesPaint(0, color);
    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);

    ValueAxis yAxis = plot.getRangeAxis();
    yAxis.setRange(0, 150);//  w w  w.j  av a2s . c o m
    ValueAxis xAxis = plot.getDomainAxis();
    xAxis.setAutoRange(true);
    xAxis.setFixedAutoRange(5 * MINUTE);
    return chart;
}

From source file:com.intel.stl.ui.common.view.ComponentFactory.java

public static JFreeChart createXYAreaSparkline(XYDataset dataset) {
    JFreeChart jfreechart = ChartFactory.createXYAreaChart(null, null, null, dataset, PlotOrientation.VERTICAL,
            false, false, false);/*from  w ww.  j a  v  a2 s.  c  om*/
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    xyplot.setDomainPannable(true);
    xyplot.setBackgroundPaint(null);
    xyplot.setOutlinePaint(null);
    xyplot.setForegroundAlpha(0.8F);
    xyplot.setDomainGridlinesVisible(false);
    xyplot.setDomainCrosshairVisible(false);
    xyplot.setRangeGridlinesVisible(false);
    xyplot.setRangeCrosshairVisible(false);

    DateAxis dateaxis = new DateAxis("");
    dateaxis.setTickLabelsVisible(false);
    dateaxis.setTickMarksVisible(false);
    dateaxis.setAxisLineVisible(false);
    dateaxis.setNegativeArrowVisible(false);
    dateaxis.setPositiveArrowVisible(false);
    dateaxis.setVisible(false);
    xyplot.setDomainAxis(dateaxis);

    ValueAxis rangeAxis = xyplot.getRangeAxis();
    rangeAxis.setTickLabelsVisible(false);
    rangeAxis.setTickMarksVisible(false);
    rangeAxis.setAxisLineVisible(false);
    rangeAxis.setNegativeArrowVisible(false);
    rangeAxis.setPositiveArrowVisible(false);
    rangeAxis.setVisible(false);

    XYItemRenderer xyitemrenderer = xyplot.getRenderer();
    xyitemrenderer.setSeriesPaint(1, UIConstants.INTEL_DARK_GRAY);
    xyitemrenderer.setSeriesPaint(0, NodeTypeViz.SWITCH.getColor());
    return jfreechart;
}

From source file:com.view.TimeSeriesChartView.java

public JFreeChart getTimeSeriesChart(Excel theExcel, ReceivingControl theRC) {

    System.out.println(theRC.getNumberOfItem());
    System.out.println(theRC.getNumberOfSite());
    System.out.println(theRC.getNumberOfVendor());
    System.out.println(theRC.getVendorInfo());
    System.out.println(theRC.getSiteInfo());
    System.out.println(theRC.getItemInfo());

    //        TimeSeries item1_xy_data = new TimeSeries("Item1");
    //        TimeSeries item2_xy_data = new TimeSeries("Item2");
    //        TimeSeries item3_xy_data = new TimeSeries("Item3");
    ArrayList<Receiving> theReceiving = theExcel.getSheetReceiving();

    //        HashMap<Month, Integer> item1Map = new HashMap<>();
    //        HashMap<Month, Integer> item2Map = new HashMap<>();
    //        HashMap<Month, Integer> item3Map = new HashMap<>();

    TimeSeries data[] = new TimeSeries[theRC.getNumberOfItem()];
    HashMap<Month, Integer> itemMap[] = new HashMap[theRC.getNumberOfItem()];
    for (int i = 0; i < theRC.getNumberOfItem(); i++) {
        String itemName = "item" + i;
        data[i] = new TimeSeries(itemName);
        itemMap[i] = new HashMap<>();
    }/* w ww  .j  a va  2s  .  c  o  m*/
    Calendar cal = Calendar.getInstance();
    for (int i = 0; i < theReceiving.size(); i++) {
        cal.setTime(theReceiving.get(i).getDate());
        int month = cal.get(Calendar.MONTH) + 1;
        int year = cal.get(Calendar.YEAR);
        int quantity = theReceiving.get(i).getQuantity();
        Month theMonth = new Month(month, year);
        int itemNum = theReceiving.get(i).getItem() - 1;
        itemMap[itemNum].put(theMonth, updateItemMap(itemMap[itemNum], theMonth, quantity));
        //            if (theReceiving[i].getItem() == 1)
        //            {
        //                item1Map.put(theMonth, updateItemMap(item1Map, theMonth, quantity));
        //            }
        //            else if (theReceiving[i].getItem() == 2)
        //            {
        //                item2Map.put(theMonth, updateItemMap(item2Map, theMonth, quantity));
        //            }
        //            else if (theReceiving[i].getItem() == 3)
        //            {
        //                item3Map.put(theMonth, updateItemMap(item3Map, theMonth, quantity));
        //            }
    }
    TimeSeriesCollection my_data_series = new TimeSeriesCollection();
    for (int i = 0; i < theRC.getNumberOfItem(); i++) {
        for (Map.Entry<Month, Integer> entry : itemMap[i].entrySet()) {
            data[i].add(entry.getKey(), entry.getValue());
        }
        my_data_series.addSeries(data[i]);
    }

    // add series using addSeries method
    //        my_data_series.addSeries(item1_xy_data);
    //        my_data_series.addSeries(item2_xy_data);
    //        my_data_series.addSeries(item3_xy_data);        
    JFreeChart chart = ChartFactory.createTimeSeriesChart("Receiving", "Month", "Quantity", my_data_series,
            true, true, false);
    chart.setBackgroundPaint(Color.YELLOW);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.WHITE);
    plot.setDomainGridlinePaint(Color.GREEN);
    plot.setRangeGridlinePaint(Color.orange);
    plot.setAxisOffset(new RectangleInsets(50, 0, 20, 5));
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();

    renderer.setBaseShapesVisible(true);
    renderer.setBaseShapesFilled(true);

    DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("MM.yyyy"));
    return chart;
}

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

/**
 * Creates the demo chart.//w  ww  . j  ava 2s .  com
 * 
 * @return The chart.
 */
protected JFreeChart createChart(XYDataset dataset) {
    JFreeChart chart1 = ChartFactory.createTimeSeriesChart(chartTitle, domainLabel, //"Time of Day", 
            rangeLabel, //"Value",
            dataset, !legendPanelOn, true, false);

    chart1.setBackgroundPaint(Color.white);
    XYPlot plot = chart1.getXYPlot();
    plot.setOrientation(PlotOrientation.VERTICAL);
    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.setDomainCrosshairLockedOnData(false);
    plot.setRangeCrosshairVisible(false);
    XYItemRenderer renderer = plot.getRenderer();
    renderer.setBasePaint(Color.black);
    renderer.setLegendItemLabelGenerator(new SOCRXYSeriesLabelGenerator());

    //         setXSummary(dataset); X is time
    return chart1;
}

From source file:org.infoglue.deliver.util.charts.TimeSeriesDiagram.java

/**
 * Creates a chart.//from w  w  w  .  j  av  a2s.c  o  m
 * 
 * @param dataset  a dataset.
 * 
 * @return A chart.
 */

private JFreeChart createChart(XYDataset dataset) {
    JFreeChart chart = ChartFactory.createTimeSeriesChart(header, axisXHeader, axisYHeader, dataset, true, true,
            false);

    chart.setBackgroundPaint(Color.white);

    LegendTitle legend = chart.getLegend();
    //legend.set .setDisplaySeriesShapes(true);

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

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

    DateAxis axis = (DateAxis) plot.getDomainAxis();

    if (this.timeGranulariry.equalsIgnoreCase("Week")) {
        DateTickUnit unit = new DateTickUnit(DateTickUnit.DAY, 7, new SimpleDateFormat(this.dateFormat));
        axis.setTickUnit(unit);
        axis.setTickMarkPosition(DateTickMarkPosition.START);

        axis.setDateFormatOverride(new SimpleDateFormat(this.dateFormat));
    } else {
        axis.setDateFormatOverride(new SimpleDateFormat(this.dateFormat));
    }
    /*
    DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat(this.dateFormat));
      */
    return chart;

}

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

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

    // create the chart...
    final JFreeChart chart = ChartFactory.createXYLineChart("Line Chart Demo 2", // chart title
            "X", // x axis label
            "Y", // y axis label
            dataset, // data
            PlotOrientation.HORIZONTAL, true, // include legend
            true, // tooltips
            false // urls
    );

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    chart.setBackgroundPaint(Color.white);

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

    // get a reference to the plot for further customisation...
    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.setDomainCrosshairLockedOnData(true);
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairLockedOnData(true);
    plot.setRangeCrosshairVisible(true);

    final StandardXYItemRenderer renderer = (StandardXYItemRenderer) plot.getRenderer();
    renderer.setPlotShapes(true);
    renderer.setShapesFilled(true);
    renderer.setItemLabelsVisible(true);
    final ItemLabelPosition p = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BOTTOM_CENTER,
            TextAnchor.CENTER, Math.PI / 4);
    renderer.setPositiveItemLabelPosition(p);

    // 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.n52.oxf.render.sos.TimeSeriesChartRenderer4xPhenomenons.java

public JFreeChart renderChart(OXFFeatureCollection observationCollection, ParameterContainer paramCon) {
    // which observedProperty has been used?:
    ParameterShell observedPropertyPS = paramCon.getParameterShellWithServiceSidedName("observedProperty");
    if (observedPropertyPS.hasMultipleSpecifiedValues()) {
        observedProperties = observedPropertyPS.getSpecifiedTypedValueArray(String[].class);
    } else if (observedPropertyPS.hasSingleSpecifiedValue()) {
        observedProperties = new String[] { (String) observedPropertyPS.getSpecifiedValue() };
    } else {/*from   w  w w. j  a  va 2 s .c o  m*/
        throw new IllegalArgumentException("no observedProperties found.");
    }

    String[] foiIdArray;
    ParameterShell foiParamShell = paramCon.getParameterShellWithServiceSidedName("featureOfInterest");
    if (foiParamShell.hasMultipleSpecifiedValues()) {
        foiIdArray = foiParamShell.getSpecifiedTypedValueArray(String[].class);
    } else {
        foiIdArray = new String[] { (String) foiParamShell.getSpecifiedValue() };
    }

    ObservationSeriesCollection tuples4FOI = new ObservationSeriesCollection(observationCollection, foiIdArray,
            observedProperties, false);

    JFreeChart chart = ChartFactory.createTimeSeriesChart(null, // title
            "Date", // x-axis label
            observedProperties[0], // y-axis label
            createDataset(foiIdArray, tuples4FOI, 0), // data
            true, // create legend?
            true, // generate tooltips?
            false // generate URLs?
    );

    chart.setBackgroundPaint(Color.white);

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

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

    // add additional datasets:

    DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat());

    for (int i = 1; i < observedProperties.length; i++) {
        XYDataset additionalDataset = createDataset(foiIdArray, tuples4FOI, i);
        plot.setDataset(i, additionalDataset);
        plot.setRangeAxis(i, new NumberAxis(observedProperties[i]));
        plot.getRangeAxis(i).setRange((Double) tuples4FOI.getMinimum(i), (Double) tuples4FOI.getMaximum(i));
        plot.mapDatasetToRangeAxis(i, i);
    }

    return chart;
}

From source file:com.bitplan.vzjava.Plot.java

/**
 * Creates a chart./* w  ww.  j  av a 2  s  . c o  m*/
 * 
 * @param dataset
 *          a dataset.
 * 
 * @return A chart.
 */
private JFreeChart createChart(final ColoredDataSet cdataset) {

    final JFreeChart chart = ChartFactory.createTimeSeriesChart(title, "Time", "Power", cdataset.dataSet, true,
            true, false);

    chart.setBackgroundPaint(Color.white);

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

    final XYPlot plot = chart.getXYPlot();
    // plot.setOutlinePaint(null);
    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(false);

    final XYItemRenderer renderer = plot.getRenderer();
    if (renderer instanceof StandardXYItemRenderer) {
        renderer.setSeriesStroke(0, new BasicStroke(3.0f));
        renderer.setSeriesStroke(1, new BasicStroke(3.0f));
    }

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

    // http://www.jfree.org/jfreechart/api/gjdoc/org/jfree/chart/plot/DefaultDrawingSupplier-source.html
    DrawingSupplier supplier = new DefaultDrawingSupplier(cdataset.paintSequence,
            DefaultDrawingSupplier.DEFAULT_OUTLINE_PAINT_SEQUENCE,
            DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE,
            DefaultDrawingSupplier.DEFAULT_OUTLINE_STROKE_SEQUENCE,
            DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE);
    chart.getPlot().setDrawingSupplier(supplier);
    return chart;
}